Java中的上下文切换 [英] Context switching in Java

查看:140
本文介绍了Java中的上下文切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多线程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.

  • 是否有一种方法可以精确地标识Java中的上下文切换位置(对于不同的运行情况,位置会有所不同)?

  • 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?

推荐答案

您的问题的简短答案是You can not do it in java.JVM有责任根据基础操作系统和内存模型切换上下文.

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_(计算)

这篇关于Java中的上下文切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆