java基础
pengpeng11
这个作者很懒,什么都没留下…
展开
-
UDP连接
[code="java"] public class TestUDPServer { public static void main(String[] args) throws Exception { byte[] buf = new byte[1024]; //接受客户端数据存入buf中 DatagramPack...原创 2009-09-13 12:56:29 · 103 阅读 · 0 评论 -
线程同步
[code="java"] public class Timer { private static int num = 0; public synchronized void add(String name) { //在执行这个方法过程中,当前对象被锁定 num ++; try { Thread.sleep(1); } catch (Interrupted...原创 2009-09-06 20:21:21 · 77 阅读 · 0 评论 -
线程优先线设置
[code="java"] public class TestPriority { public static void main(String[] args) { Thread t1 = new Thread(new T1()); Thread t2 = new Thread(new T2()); t1.setPriority(Thread.NORM_PRIORI...原创 2009-09-06 00:37:08 · 94 阅读 · 0 评论 -
线程yield()
[code="java"] public class TestYield { public static void main(String[] args) { Runnable4 r4 = new Runnable4("r4"); Runnable4 r5 = new Runnable4("r5"); r4.start(); r5.start(); ...原创 2009-09-06 00:36:12 · 79 阅读 · 0 评论 -
线程Join()
[code="java"] public class TestJoin { public static void main(String[] args) { Runnable3 r3 = new Runnable3(); Thread t = new Thread(r3); t.start(); try { t.join();//合并某个线程 等子线...原创 2009-09-06 00:34:29 · 84 阅读 · 0 评论 -
线程sleep方法
[code="java"] public class Runnable2 implements Runnable{ public void run() { while (true) { System.out.println("----" + new Date()+"======="); try { Thread.sleep(1000); } ...原创 2009-09-06 00:32:44 · 78 阅读 · 0 评论 -
Email格式验证
[code="java"] public class EmailSpider { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new FileReader( "D:\\test.txt")); String line =...原创 2009-01-11 17:04:44 · 237 阅读 · 0 评论 -
String.split()要注意的几点
在java.lang包中有String.split()方法,返回是一个数组 我在应用中用到一些,给大家总结一下,仅供大家参考: 1、如果用“.”作为分隔的话,必须是如下写法:String.split("\\."),这样才能正确的分隔开,不能用String.split("."); 2、如果用“|”作为分隔的话,必须是如下写法:String.split("\\|"),这样才能正确的分隔开,不能用...原创 2009-06-19 10:33:31 · 92 阅读 · 0 评论 -
Sql Server2000和2005的连接代码区别
[code="java"] 写连接代码时需要注意2000和2005的不同: 1、连接SqlServer2000 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); URL = "jdbc:microsoft:sqlserver://localhost:1433;Datab...原创 2009-09-14 13:58:54 · 98 阅读 · 0 评论 -
线程死锁例子
[code="java"] public class TestDeadLock implements Runnable{ public int flag = 1; static Object obj1 = new Object(),obj2 = new Object(); public void run() { System.out.println("flag= "+fl...原创 2009-09-06 20:41:12 · 82 阅读 · 0 评论