java??????в????????С????
???????????? ???????[ 2013/5/31 9:57:50 ] ????????
???????????????????????????????????????????????????????????????synchronized????????????????????????????????е???????????????????????????????????????У????????й????????????????????????????????????????У??????????й??????ù???????????????????????????????????????????????????????private???????????????????????????????????????????????????????裡???????????????????????ù?????????в??????????????????????????????????м?????????????Timer??????????????????????????????????????????????????????TimeTask??????????
package xinyu.shangrao.demo.fucking;
import java.util.Date;
import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
public class ThreadDemoNew {
public static void main(String[] args) throws ParseException {
long counter;
/* Date date = null;
String s = "2013-05-29 ????08:26 ";
SimpleDateFormat sdf = new SimpleDateFormat();
date = sdf.parse(s);
System.out.println("------??????????Date??parse------");
System.out.println(" " +date.getTime() );
counter=date.getTime();
System.out.println(" " + date ); */
Date tim=new Date();
counter=tim.getTime();
tim.setTime(counter+9000);
new Timer().schedule(new TimerTask(){ //???????????????????????????????????
public void run(){
System.out.println("?????");
System.exit(0);
}
}?? tim );
EventKey ke=new EventKey();
Thread1 demo1=new Thread1(ke) ;
Thread2 demo2=new Thread2(ke) ;
demo1.start();
demo2.start();
}
}
class Thread1 extends Thread{
private EventKey ek;
private int ko;
public Thread1(EventKey e){
ek=e;
}
public void run(){
synchronized(this){
while(true){
ko=ek.next();
System.out.println(Thread.currentThread()+"ko:"+ko);
if(ko % 2 !=0 ){
System.out.println("???????????");
System.exit(0);
}
}}}
}
class Thread2 extends Thread{
private EventKey ek;
private int ko;
public Thread2(EventKey e){
ek=e;
}
public void run(){
synchronized(this){
while(true){
ko=ek.next();
System.out.println(Thread.currentThread()+"ko:"+ko);
if(ko % 2 !=0 ){
System.out.println("???????????");
System.exit(0);
}
}}}
}
class EventKey implements IntGenerator{
private int i=0;
synchronized public int next(){
i++;
i++;
try{
TimeUnit.MILLISECONDS.sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
return i;
}
}
interface IntGenerator{
public int next();
}
??????????н?????????????в??????????????????????????????г?????????????????????????Ч????????????????????????в?θУ?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11