📄 doprotected.java
字号:
import javax.microedition.midlet.*;
public class DoProtected extends MIDlet{
int data = 0;
SetThread setThread;
GetThread getThread;
Monitor monitor;
boolean settable = false;
public DoProtected(){
setThread = new SetThread();
getThread = new GetThread();
monitor = new Monitor();
}
public void startApp(){
getThread.start();
setThread.start();
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
class SetThread extends Thread{
public void run(){
while(data != 10){
monitor.set();
}
System.out.println("SetThread Exit!");
}
}
class GetThread extends Thread{
public void run(){
while(data != 10){
for(int i=0;i<1000;i++){}
monitor.get();
}
System.out.println("GetThread Exit!");
}
}
class Monitor{
public synchronized void set(){
while(!settable){
try{
wait();
}
catch(Exception ex){}
}
data++;
System.out.println("Set data = "+data);
settable = false;
notify();
}
public synchronized void get(){
while(settable){
try{
wait();
}
catch(Exception ex){}
}
System.out.println("Get data = "+data);
settable = true;
notify();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -