I’m not sure if I’m just missing something here, but is it possible to pass a variable into a running Thread in java? The variables may change and may need to be resent into the same thread.
Any tutorials on the matter or examples would be great.
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.
You have two easy choices:
ConcurrentLinkedQueue: this can act like a threadsafe pipe between two threads. On thread feeds the queue as needed, the other reads as
needed, either blocking or polling.
use shared variables and flags, and use synchronization primitives to ensure that a thread is not reading while another is writing.