1
私は2つのクラスを持っています。 Class1では私はスレッドを持っていて、Class2ではそのスレッドを一時停止/ロックしなければなりません。このスレッドはログイン直後に開始されます。私のシナリオでは、ログイン後(Class2で実装されています)、スレッドはさらにいくつかのログインを待ち、DBからデータを取得する必要があります。別のクラスから実行中のスレッドを制御する方法を教えてください。別のクラスで実行中のスレッドをロック/ポーズする方法は?
のClass1:
public class Class1{
Class2 cls2 = new Class2();
cls2.logon();
// login which will start the thread in the Class2 as well
// Please suggest what should be done here
// DB realated stuff need be done here
// Have to unlock/resume the thread in Class2
}
クラス2:
public class Class2{
public void receiveMessage(String str){
new StringProcessor(str);
}
public class StringProcessor implements Runnable {
//do some stuff but have to wait for the DB related stuff in Class1
}
public void logon(){
//Will create/logon the connection and the message will be start arriving
}
}
実際にログインした後にメッセージを受信するTCP/IP接続が存在します。メソッドreceiveMessage()は、メッセージが到着するたびに呼び出されます。しかし、私はそれを一時停止する必要があります
乾杯、 サクシー。 S
Class1とClass2の完全な関係を持つようにコードサンプルを完成してください –