javaのインターラプトについて質問します。 Q1)下記のコードで、aaaRunクラスの中に、rcvInterruptクラスを入れることは出来ますか? 以上、宜しくお願いします。 //============== //Project:T_thread Interrupt(受信側セット)の確認 public class T_thread extends Thread{ public static void main(String args[]){ rcvInterrupt obj=new rcvInterrupt(); obj.start(); for (int i = 0 ; i < 20 ; i++){ //20回の1msタイマー待ち try{ Thread.sleep(1); System.out.println("main: 20回の1msタイマー待ち"); }catch(InterruptedException e){ } } //for } //main } //T_thread //割込の発生側のクラス class genInterrupt extends T_thread{ private Thread target; //コンストラクター genInterrupt(Thread targetx){ this.target=targetx; //target=targetx; } //コンストラクターの次にrun()の記載 public void run(){ //inherit_myDrawClass inherit=new inherit_myDrawClass(); //inherit.runX(); System.out.println("genInterupt start"); for (int i=0; i<10; i++){ try{ Thread.sleep(2); //割込み信号の発生:受信先は、このスレッドの起動を行なった所に記載ズミ target.interrupt(); } catch(InterruptedException e){ } }//for } //public void run(){ } //class genInterupt extends Thread{ //class aaaRun{ **************************** //割込の受信側のクラス class rcvInterrupt extends T_thread{ int cnt=0; public void run(){ //run()の前に記載は、文法エラーになる genInterrupt obj=new genInterrupt(Thread.currentThread()); obj.setPriority(Thread.MAX_PRIORITY); obj.start(); System.out.println("receiveInterupt start"); for (int i=0 ; i<20 ; i++){ try{ Thread.sleep(2); }catch(InterruptedException e){ System.out.println("get interrupt cnt="+cnt++); } } } //public void run(){ } //class rcvInterupt //} ************************
↧