当前线程方法 java [英] Current Thread Method java

查看:53
本文介绍了当前线程方法 java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用线程来制作我正在制作的游戏.我对这个主题非常,所以我可能无法正确理解.我的问题是 currentThread() 方法如何在 java API 的 Thread 类中工作.API 说返回对当前正在执行的线程对象的引用.",但据我所知,多个线程同时运行.怎么可能只返回一个正在执行的线程?

So I am trying to work with threads for a game I am making. I am very new to the subject so I may not understand correctly. My question is how does the currentThread() method work in the Thread class of the java API. The API says "Returns a reference to the currently executing thread object.", but as far as I understand multiple threads run at the same time. How is it possible to return only one executing thread?

推荐答案

调用 currentThread 的代码将在其中一个线程中执行,而不是在所有线程中执行,因此它可以获取该线程

The code that calls currentThread will be executing in one of the threads, not in all of them, so it can get that thread specifically.

这篇关于当前线程方法 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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