Friday, 15 April 2011

multithreading - Access/Modification of Global hashmap and string inside the threads in Java -



multithreading - Access/Modification of Global hashmap and string inside the threads in Java -

i wrote programme in java reservation scheme 3 medical clinics in quebec. experimental project myself.

clients connect server through rmi (remote method invocation)

it has 3 synchronized hashmaps ,one each clinic , defined protected after whole class of server implementation starts (which means should visible other classes , ... within server implementation class.)

for checking reservation function, server creates 3 runnable threads communicate through same udp socket on specific port defined outside thread invocation , passed within communicating threads (thread 1 send timeslot(which passed client server through rmi , passed outside thread within of it) using udp socket communication , timeslot used in each server hashmap sent 2 other threads them own hashmap it.

the udp works fine , sends timeslot , receiving threads receive it, noticed if utilize popular getter , setter, or if pass whole hashset threads did passing sockets udp, hashmap not visible threads.

for example, if reserve timeslot specific patiend within hashmap of specific clinic, lets montreal clinic, if check hashmap using if(montrealclinic.containsvalue(timeslot) outside of threads, works fine , shows timeslot reserved on montrealclinic hashmap, when check within of thread, has no compile time error, returns not reserved!

also defined global string outside threads store lookup result happens within runnable thread (implements runnable) , never modification coded within of thread, , modification of outside of threads work! when access hashmap , string using getter , setter functions defined outside thread , accessed within thread.

how can access global hashmap defined outside threads within of it? , how can modify final result defined , returned outside thread within thread?

thanks alot

java multithreading hashmap global-variables runnable

No comments:

Post a Comment