English 中文(简体)
简明信
原标题:Simple Threads Behaviour in Java
/* Multiple Threads Executing
 * Author Myth17
 */

class T1 implements Runnable
{
    public void run()
    {
        for(int c=0;c<10;c++)
        System.out.println(Thread.currentThread().getName()+" running....");
    }
}

class T2 implements Runnable
{
    public void run()
    {
        for(int c=0;c<10;c++)
        System.out.println(Thread.currentThread().getName()+" running....");
    }
}


class T3 implements Runnable
{
    public void run()
    {
    for(int c=0;c<10;c++)   
    System.out.println(Thread.currentThread().getName()+" running....");    
    }
}

class Rt
{
    public static void main(String args[])
    {
        T1 j1=new T1();
        T2 j2=new T2();
        T3 j3=new T3();

        Thread w1=new Thread(j1);
        w1.setName("S");
        Thread w2=new Thread(j2);
        w2.setName("N");
        Thread w3=new Thread(j3);
        w3.setName("M");

        w1.start();
        w2.start();
        w3.start();
    }
}

如果在3个地方的休息室里休息最多3个,则在北海滨海,每个胎面都按SSSNNNMMM(9条线)先后进行。

我改变了住处,每处就有10处。 我期待有30条线路,秩序发生变化。 但奇怪的是,S从来就没有执行和退出方案!

是否应该更早获得机会? 正如我所理解的那样,除了 de门外,只有用户读完后才能关闭。

alt text http://img36.imageshack.us/img36/6646/69458021.png

最佳回答

您认识到,在您的产出中,有8条N10条M。 产出窗口似乎只显示18条线。 但你看不到。

您可尝试incrementing loop to 20,而不是10。 我猜想你只见18 Line of M

(问题似乎不是在产出窗口上设置滚动条码。) 如果存在,应恢复工作。

问题回答

在座椅上,read子都没有 da。 直到你通过

回答你们的问题!

这本应行之有效。 您可在<代码>run()方法中登录,或用断点加以压缩。

你只有18条线显示在窗口。

所有的“S”线路以及两个“N”线已经开脱。

I tried running your code on a Windows Sun JVM 1.6 and as expected, I got 30 lines. What kind of JVM are you using? All non daemon threads should finish before the JVM exists.





相关问题
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 ...

热门标签