Suppose I have thread A and B running. How can I “call” a method from thread B such that the method is executed in thread A?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To do this, thread A must implement some sort of request-queueing mechanism onto which thread B can enqueue a request. Thread A must also provide a loop where it polls the request queue to dequeue and execute requests
This is standard producer-consumer architecture and is done, for example, when you use Swing Worker tasks that get run on their own threads, or when you all
SwingUtilities.invokeLater()which runs tasks on the EDT.