multithreading - How to share variables between two threads in Java? -
this question has answer here:
- how share variable between 2 threads 3 answers
- java share variable between 2 threads 4 answers
i beginner learning java. have question, me solve it? :)
i have class named server maintains hashmap variable, , has 2 methods named send() , receive(). want 2 methods run concurrently. send() method use hashmap variable , receive() method change hashmap variable.
please work out. lot!
define hashmap in main thread spawns send , receive threads. make sure use synchronizedmap don't run race condition.
Comments
Post a Comment