Context switching in Java

感情迁移 提交于 2019-12-12 12:13:12

问题


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?


回答1:


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)




回答2:


Most context switching are caused by external interrupts (including timer). It can happen at any instruction. Indeed, distribution is not even, but very random. Even if you could collect probability distribution of context switching for every instruction, how would you use it? Looks like you try to solve some problem with inadequate means. Better tell what your real problem is, and we try to suggest a solution.



来源:https://stackoverflow.com/questions/18964050/context-switching-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!