计算机网络课设报告,java平台实现,Java;HTTP;Web服务器
阻塞解除条件为其它线程调用该资源的notify()或notifyAll()。
下面一个例子实践了如何通过上述两种方法创建线程并启动它们:
// 通过Thread类的子类创建的线程;
class thread1 extends Thread
{ file://自定义线程的run()方法;
public void run()
{
System.out.println("Thread1 is running…");
}
}
file://通过Runnable接口创建的另外一个线程;
class thread2 implements Runnable
{ file://自定义线程的run()方法;
public void run()
{
System.out.println("Thread2 is running…");
}
}
file://程序的主类'
class Multi_Thread file://声明主类;
{
plubic static void mail(String args[]) file://声明主方法;
{
thread1 threadone=new thread1(); file://用Thread类的子类创建线程; Thread threadtwo=new Thread(new thread2()); file://用Runnable接口类的对象创建线程;
threadone.start(); threadtwo.start(); file://strat()方法启动线程;
}
}
运行该程序就可以看出,线程threadone和threadtwo交替占用CPU,处于并行运行
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库简单Web服务器设计与实现课程设计(8)在线全文阅读。
相关推荐: