什么';s java线程和系统线程之间的关系

什么';s java线程和系统线程之间的关系,java,android,linux,ipc,Java,Android,Linux,Ipc,最近,我研究了Android系统中的Handler类。在我看来,处理程序机制是线程运行一个死循环,并在该死循环中重复从队列中检索消息,然后将消息发送给目标处理程序 但当队列中没有消息时,线程必须等待或阻塞指定的时间,这可以减少CPU时间。我的理解是,为了在指定的时间内等待或阻止线程,它使用linux epoll函数在本机层中等待指定的时间。然后,当队列中有消息时,它使用linux管道唤醒线程 所以我的困惑是,为什么Android系统使用Linux进程通信功能(IPC)来控制Java线程等待或唤醒

最近,我研究了Android系统中的
Handler
类。在我看来,
处理程序
机制是
线程
运行一个死循环,并在该死循环中重复从队列中检索消息,然后将消息发送给目标处理程序

但当队列中没有消息时,线程必须等待或阻塞指定的时间,这可以减少CPU时间。我的理解是,为了在指定的时间内等待或阻止
线程
,它使用linux epoll函数在本机层中等待指定的时间。然后,当队列中有消息时,它使用linux管道唤醒线程

所以我的困惑是,为什么Android系统使用Linux进程通信功能(IPC)来控制Java线程等待或唤醒?Java
线程与系统线程或linux线程之间的关系是什么

换句话说,我真正想知道的是为什么android使用linux ipc函数来控制java线程,以实现所谓的处理程序,该处理程序用于在java线程之间发送消息。

这是你的电话号码

publicstaticvoidloop(){
最终活套me=myLooper();
如果(me==null){
抛出新的RuntimeException(“此线程上未调用任何Looper;Looper.prepare()”);
}
final MessageQueue=me.mQueue;
//确保此线程的标识是本地进程的标识,
//并跟踪身份标记的实际内容。
Binder.clearCallingIdentity();
最终长标识=活页夹。clearCallingIdentity();
对于(;;){
Message msg=queue.next();//可能会阻塞
如果(msg==null){
//无消息表示消息队列正在退出。
返回;
}
//如果用户界面事件设置记录器,则必须在局部变量中
打印机日志记录=me.mloging;
if(记录!=null){
logging.println(“>>>分派到“+msg.target+”)+
msg.callback+“:”+msg.what);
}
msg.target.dispatchMessage(msg);
if(记录!=null){

logging.println(“在阅读了您的问题之后,我的好奇心让我想到了。我相信对于使用Linux进程通信函数(IPC)来控制Java线程存在误解

我不相信我能更好地解释链接中给出的美丽描述


为什么所有的否决票?对我来说似乎是一个非常有效的问题。用a+1来取消其中一些。@Simon,谢谢你的支持。@Simon否决票是一个信号,这个问题很难理解。如果你认为这是一个好问题,那么编辑这个问题会有帮助,以便其他人可以看到。只是评论是不行的(始终)我真的很想知道jvm中的线程与linux线程或系统线程之间的关系是什么,linux系统中的java线程对应的是什么?为什么Android可以使用linux IPC和epoll来控制java线程被JNI以本机方式等待或阻止。提供的文章非常好,我理解Android平台。但我真正想知道的是为什么android使用linux ipc函数控制java线程来实现所谓的处理程序,用于在java线程之间发送消息。@KrystaJake我不是android人,我只是出于好奇才研究它。希望我们能很快得到更好的答案,让我们再给它一些时间。
public static void loop() {
        final Looper me = myLooper();
        if (me == null) {
            throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
        }
        final MessageQueue queue = me.mQueue;

        // Make sure the identity of this thread is that of the local process,
        // and keep track of what that identity token actually is.
        Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();

        for (;;) {
            Message msg = queue.next(); // might block
            if (msg == null) {
                // No message indicates that the message queue is quitting.
                return;
            }

            // This must be in a local variable, in case a UI event sets the logger
            Printer logging = me.mLogging;
            if (logging != null) {
                logging.println(">>>>> Dispatching to " + msg.target + " " +
                        msg.callback + ": " + msg.what);
            }

            msg.target.dispatchMessage(msg);

            if (logging != null) {
                logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
            }

            // Make sure that during the course of dispatching the
            // identity of the thread wasn't corrupted.
            final long newIdent = Binder.clearCallingIdentity();
            if (ident != newIdent) {
                Log.wtf(TAG, "Thread identity changed from 0x"
                        + Long.toHexString(ident) + " to 0x"
                        + Long.toHexString(newIdent) + " while dispatching to "
                        + msg.target.getClass().getName() + " "
                        + msg.callback + " what=" + msg.what);
            }

            msg.recycle();
        }
    }