简体   繁体   中英

Custom Event Listener for Multi threaded environment in Java Using Wait() and notify()

I have a multithreaded environment and I want to handle all threads using the event listener.

I have made the listener which will listen to the events, My question is that i want to wait and notify each thread using some specific unique id or whatever we can use for uniqueness purpose.

I am new in event listener programming in java.

I am making IVR application with Java and on each call my new thread will be created.

Any demo will be highly useful for me.

This wont directly fit to your code, you have to work to fit to you.

This is my idea.

public class MyThread extends Thread{
private static int uniqueId;
private int myId;
MyThread(){
    myId = ++uniqueId;
}
//getters and setters to myId

}

public class YourClass{

public HashMap threads = new HashMap();// use this to map your threads by ids

//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.

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM