synchronized, wait(), notify()
解决方案 »
- 请教一下void问题
- <html:img page="<bean:write name="personalInfo" property="headPic"/>"/>就出错,改成<img src>就不出错,怎么办
- 如何判断一个字符串中是否包含另一个字符串?
- 一个让人头疼的问题
- 关于倒计时
- 包的困惑
- JasperReport整合iReport的问题
- Kosling每日提问之2004.03.15!望高手指点!
- 帮忙看一下程序,关于串口操作的(急!!!在线等待)
- tomcat4 怎样配置呀?如果能够的话jb5怎样用tomcat4呀?
- 高手,如何在JBuilder6下,创建Hello,Java!工程,有*.jpx,*.java等等文件,麻烦具体点,菜鸟希望高手能伸出援助之手!
- 入门问题--Java能做什么?
但是现在已经废除了,所以需要自己写扩展类class CustomThread extends Thread
{
volatile boolean goFlag = true;
CustomThread(String name)
{
super(name);
start();
} public void run()
{
try {
for(int loop_index = 0; loop_index <= 5; loop_index++) {
System.out.println(Thread.currentThread().getName() + " here...");
Thread.sleep(500);
synchronized(this) {
while(!goFlag) {
wait();
}
}
}
} catch (InterruptedException e) {}
} public void newSuspend()
{
goFlag = false;
} synchronized public void newResume()
{
goFlag = true;
notify();
}
}class suspend
{
public static void main(String args[])
{
CustomThread thread1 = new CustomThread("one");
CustomThread thread2 = new CustomThread("two"); try {
Thread.sleep(1000);
System.out.println("Suspending thread one...");
thread1.newSuspend();
Thread.sleep(1000);
System.out.println("Resuming thread one...");
thread1.newResume();
} catch (InterruptedException e) {} try {
thread1.join();
thread2.join();
} catch (InterruptedException e) {}
}
}
把程序贴给你,希望对你有帮助