multithreading - What happens when a synchronized method is accessed at the same time in java? -
ok, trying build script automate tests on x amount of machines...and want them talk 1 another. bit new thread , have done research using synchronized methods. question is, happens when 2 separate threads try access it? understand locks , gives caller exclusive access, next call in line processed directly after it? have multiple threads call same function @ same time , want prepared handle it. found bit of information:
when method called, jvm creates stack frame call in executing thread. frame contains of local variables declared in method. in case of method, static or otherwise, doesn't access fields, each execution proceeds independently on each thread. if method uses parameters in calculation, these parameters located in stack frame, , multiple calls don't interfere each other.
this said in post , not in reference synchronized method. sorry if not making myself clear, want make sure function called thread, treated stack.
if have synchronized method, , x threads try access @ same time, magic, 1 gets access , others wait (block) until 1 has access finished it. if thread allowed inside synchronized method never exits block, have called deadlock.
Comments
Post a Comment