English 中文(简体)
Java- 要求从深处开始使用方法:它如何进入可操作的接口()?
原标题:Java - Call to start method on thread : how does it route to Runnable interface s run ()?

奥基德,我知道在 Java建造新read和翻 run的两种标准方法:

  1. 缩略语 Thread。 当“start()”法在校对时,将采用班级的操作方法。

  2. 班次从<代码>Thread中选取,从而可以推翻以下方法:) ;然后,在要求采用新的start() 方法时,该电话被转至压倒法。

在这两种方法中,基本形成了一个新的<代码>Thread物体,并采用了其启动方法。 然而,在第二种方法中,电话机制被转至用户定义的<代码>run()方法非常明确(在游戏中采用简单的操作时间多变),但我不理解对“条码”(<>启程(<>)”方法的呼唤是如何通过到<代码>run(<>>>>>>>>>>>>>>>>>界面。 <代码>Thread 类别是否有一个私人领域,即<代码>可核查,首先要加以核对,如果确定,则采用操作方法,如果该方法被设定为物体? 这将是海事组织的一个奇怪机制。

read线上的start(>>号”号接通到“Runnable接口”的操作方法,在构筑read时,其物体作为参数通过的那一类接口如何使用?

最佳回答

www.un.org/Depts/DGACM/index_french.htm 参照<代码>可更改例,并在<代码>run<>/code>的基调中将其命名。

您可在来文方看到这一点:

// passed into the constructor and set in the init() method
private Runnable target;
...
// called from native thread code after start() is called
public void run() {
    if (target != null) {
        target.run();
    }
}
问题回答

虽然你可以研究实际来源代码,但可以认为:

public class MyThread implements Runnable {
 private  Runnable r;
 public MyThread() {
 }
 public MyThread(Runnable r) {
        this.r = r;
 }

 public void start() {
   //magic to launch a new thread
   run(); // the above magic would probably call run(), rather than
          // call it directly here though.
  }
  public void run() {
    if(r != null) 
       r.run();
   }
}

简言之,如果你延长我的校对和压倒一切,你将采用你的()管理方法。 如果你采用一种可操作的手法,那么MyThread的操作()方法就只能下放到这种可操作的()方法上。

在这两种情况下,都必须有具体的校对课程。 在第一种情况下(实施可操作性),使实施该疾病的那类人能够阅读。 你们仍不得不把你的班子作为理由传给read子的建筑商。 而在第二起案件中,如果你延长校对级,情况并非如此。

当采用启动方法时,没有保证立即采用(或)操作方法。 要求一种开端方法表明,read已准备好运行。 之后,它可视马read池而定,前往任何各州。

FYI: 可操作

您本来可以仅检查<代码>的来源。 表格:

public void run() {
    if (target != null) {
        target.run();
    }
}

目标是:

private Runnable target;

但我认为,你正在寻求的真正答案是关于如何真正开展工作的细节。 不幸的是,这在土著图书馆中被忽略。 只是设法高度了解翻新工作的方式。

答案尚未探讨的一个问题是,从<代码>start(>到run(<>>>>>>/code>,两者兼而有之,是简单而复杂的。

简略地说,start(>) 方法将一种本地方法(start0 in the OpenJDK implementation)称为一种本地方法,将一些记忆用于一个新的阵列,并要求该协调员将空间作为 st和C++功能(thread_enter)作为执行功能。 这一功能反过来又把th带回 Java,在read标上称作run()。 低水平的模式(使本组织开始在 st子和功能上形成新的read线)应当为那些在定位台系统或视窗上做本土read的人熟。

细节使其更加复杂,需要处理所有错误处理和模糊的对冲案件。 如果您读到OpenJDK sources,其中特别注意read.java,JVER_StartThreadjvm.cpp,以及JavaThread/code_>>,





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...