class firstThread extends Helper1
{
Thread thread_1 = new Thread(new Runnable()
{
@Override
public void run() {
try {
for (int i = 1; i <= 20; i++) {
System.out.println("Hello World");
Thread.sleep(500);
if (i == 10) {
Notify();
Wait();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
class secondThread extends firstThread
{
Thread thread_2 = new Thread(new Runnable()
{
@Override
public void run() {
// TODO Auto-generated method stub
try {
Wait();
for(int i = 1; i<=20; i++)
{
System.out.println("Welcome");
Thread.sleep(100);
}
Notify();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
class Helper1
{
public synchronized void Wait() throws InterruptedException
{
wait();
}
public synchronized void Notify() throws InterruptedException
{
notify();
}
}
public class InheritanceClass {
public static void main(String[] args)
{
Thread f = new Thread(new firstThread().thread_1);
Thread s = new Thread(new secondThread().thread_2);
f.start();
s.start();
}
}
첫 번째 스레드에만 출력이 있습니다. 제 코드를 시험해보십시오. 나는 그것이 왜 일어나는 지 모른다. 두 번째 스레드가 출력을 제공하지 않습니다. secondThread의 Wait() 때문이라고 가정합니다. 어떻게해야할지 모르겠습니다.두 번째 스레드가 출력을 제공하지 않습니다. (java)
http://www.oracle.com/technetwork/java/codeconv-138413.html –
[방금 게시했습니다.] (http://stackoverflow.com/questions/16974206/thread-inheritance-in-java) . 나는 당신에게 코딩과 명명 규칙을 상기시켰다. 너는 그들을 무시했다. -1. – wchargin