问题描述
问题1:Thread的toString方法描述:返回该线程的字符串表示形式,包括线程名称、优先级和线程组。请问什么叫“线程组”?问题2:求一个死锁的demo,越简单越好
解决方案
线程组:http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/ThreadGroup.htm列锁例子:http://www.cnblogs.com/linjiqin/archive/2011/04/11/2013083.html希望对你有帮助
解决方案二:
死锁看这里:http://ifeve.com/deadlock/http://ifeve.com/deadlock-prevention/http://ifeve.com/reentrance-lockout/http://ifeve.com/nested-monitor-lockout/
解决方案三:
输出:t1:aquiring lock1t1:aquried lock1t2:aquiring lock2t2:aquried lock2t1:aquiring lock2t2:aquiring lock1
解决方案四:
public class DeadLock {static Object lock1 = new Object();static Object lock2 = new Object();static class Thread1 extends Thread {@Overridepublic void run() {System.out.println("t1:aquiring lock1");synchronized (lock1) {System.out.println("t1:aquried lock1");try {Thread.sleep(1000);} catch (InterruptedException e) {}System.out.println("t1:aquiring lock2");synchronized (lock2) {System.out.println("t1:aquried lock2");}}}}static class Thread2 extends Thread {@Overridepublic void run() {System.out.println("t2:aquiring lock2");synchronized (lock2) {System.out.println("t2:aquried lock2");try {Thread.sleep(1000);} catch (InterruptedException e) {}System.out.println("t2:aquiring lock1");synchronized (lock1) {System.out.println("t2:aquired lock1");}}}}public static void main(String[] args) throws InterruptedException {Thread t1 = new Thread1();Thread t2 = new Thread2();t1.start();t2.start();t1.join();t2.join();}}