Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context switching in Java

In a multi-threaded Java application, if I want to identify the instructions where the context switch from one thread to another happens, what is the best approach? Instrumenting every instruction to identify what thread is executing the instruction will give a close approximation. For example, if the switch happens after the instrumentation is executed and before the actual instr. is executed, then the result will be imprecise.

  • Is there a way to precisely identify the context switch location (which will be different for different runs) in Java?

  • What is the most cost effective of identifying this?

like image 738
user1539577 Avatar asked Nov 12 '22 21:11

user1539577


1 Answers

Short answer to your question is You can not do it in java.It is the resposibility of JVM to switch the context based on underlying operating system and memory model.

http://en.wikipedia.org/wiki/Thread_(computing)

like image 132
amicngh Avatar answered Nov 15 '22 00:11

amicngh