易截截图软件、单文件、免安装、纯绿色、仅160KB

java一个多线程的经典例子

import java.io.*;
//多线程编程 
public class MultiThread   

public static void main(String args[]) 

System.out.println("我是主线程!"); 
//下面创建线程实例thread1 
ThreadUseExtends thread1=new ThreadUseExtends(); 
//创建thread2时以实现了Runnable接口的THhreadUseRunnable类实例为参数 
Thread thread2=new Thread(new ThreadUseRunnable(),"SecondThread"); 
thread1.start();//启动线程thread1使之处于就绪状态 
//thread1.setPriority(6);//设置thread1的优先级为6 
//优先级将决定cpu空出时,处于就绪状态的线程谁先占领cpu开始运行 
//优先级范围1到10,MIN_PRIORITY,MAX_PRIORITY,NORM_PAIORITY 
//新线程继承创建她的父线程优先级,父线程通常有普通优先级即5NORM_PRIORITY 
System.out.println("主线程将挂起7秒!"); 
try 

Thread.sleep(7000);//主线程挂起7秒 

catch (InterruptedException e) 

return; 

System.out.println("又回到了主线程!"); 
if(thread1.isAlive()) 
{   
thread1.stop();//如果thread1还存在则杀掉他 
System.out.println("thread1休眠过长,主线程杀掉了thread1!"); 

else 
System.out.println("主线程没发现thread1,thread1已醒顺序执行结束了!"); 
thread2.start();//启动thread2 
System.out.println("主线程又将挂起7秒!"); 
try 

Thread.sleep(7000);//主线程挂起7秒 

catch (InterruptedException e) 

return; 

System.out.println("又回到了主线程!"); 
if(thread2.isAlive()) 
{   
thread2.stop();//如果thread2还存在则杀掉他 
System.out.println("thread2休眠过长,主线程杀掉了thread2!"); 

else 
System.out.println("主线程没发现thread2,thread2已醒顺序执行结束了!"); 
System.out.println("程序结束按任意键继续!"); 
try 

System.in.read(); 

catch (IOException e) 

System.out.println(e.toString()); 
}
}//main 
}/


相关文档:

java中的URLEncoder和URLDecoder类

【IT168 技术文档】
  /*
  网页中的表单使用POST方法提交时,数据内容的类型是 application/x-www-form-urlencoded,这种类型会:
  1.字符"a"-"z","A"-"Z","0"-"9",".","-","*",和"_" 都不会被编码;
  2.将空格转换为加号 (+) ;
  3.将非文本内容转换成"%xy"的形式,xy是两位16进制的数值;
  4.在 ......

初识Java面向对象的特性

OOP的特性主要有:1、封装;2、继承;3、多态。下面从这几个方面具体阐述。
1、封装
封装能将类的具体信息隐藏起来,使得数据得到保护。其具体实施主要是依靠访问控制机制权限,其权限主要有四种:1、private;2、default(C++没有这种权限);3、protected;4、public。在这四种权限下的数据在外界的可见性不同。Private ......

java io流总结

Java IO的一般使用原则:
一、按数据来源(去向)分类:
1、是文件: FileInputStream, FileOutputStream, FileReader, FileWriter
2、是byte[]:ByteArrayInputStream, ByteArrayOutputStream
3、是Char[]: CharArrayReader, CharArrayWriter
4、是String: StringBufferInputStream, StringReader, StringWriter
5、 ......

java 反射

通过反射创建新类示例的两种方式及比较
作者BLOG:http://blog.csdn.net/fenglibing
通过反射创建新的类示例,有两种方式:
Class.newInstance()
Constructor.newInstance()
以下对两种调用方式给以比较说明:
l             Class.newInstance() 只能 ......

java 下载文件的方法

前不久写了个下载文件的方法。经过一段时间在程序中的运用,发现了几个问题。修正一下:
public static  File saveToFiles(String destUrl,String path) throws IOException {
            final int BUFFER_SIZE = 4096;
        &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号