![](/img/trans.png)
[英]Java multi-threaded Server notify() IllegalMonitorStateException
[英]Custom Event Listener for Multi threaded environment in Java Using Wait() and notify()
我有一個多線程環境,我想使用事件監聽器處理所有線程。
我已經創建了一個將監聽事件的監聽器,我的問題是我想等待並使用一些特定的唯一ID或我們可以用於唯一目的的任何方式通知每個線程。
我是Java中事件監聽器編程的新手。
我正在用Java制作IVR應用程序,每次調用都會創建新線程。
任何演示對我都非常有用。
這不會直接適合您的代碼,您必須努力使其適合您。
這是我的主意。
public class MyThread extends Thread{
private static int uniqueId;
private int myId;
MyThread(){
myId = ++uniqueId;
}
//getters and setters to myId
}
公共課程YourClass {
公共HashMap線程= new HashMap(); //使用它通過ID映射您的線程
//when you want to access a thread, you get it from the map and call wait and notify.
//this map should be publicly visible to you.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.