publicclassMyThreadAextendsThread{private MyService myService;
publicMyThreadA(MyService myService){
super();
this.myService = myService;
}
@Overridepublicvoidrun(){
for (int i = 0 ; i < Integer.MAX_VALUE ; i++){
myService.set();
}
}
}
消费者线程:
publicclassMyThreadAextendsThread{private MyService myService;
publicMyThreadA(MyService myService){
super();
this.myService = myService;
}
@Overridepublicvoidrun(){
for (int i = 0 ; i < Integer.MAX_VALUE ; i++){
myService.set();
}
}
}
启动类:
publicclass Run {
publicstaticvoidmain(String[] args) {
MyService myService = new MyService();
MyThreadA a = new MyThreadA(myService);
a.start();
MyThreadB b = new MyThreadB(myService);
b.start();
}
}