当前位置: 技术问答>java相关
两道考题,不懂!
来源: 互联网 发布时间:2015-11-20
本文导语: public class SyncTest{ public static void main(String[] args){ final StringBuffer s1=new StirngBuffer(); final StringBuffer s2=new StirngBuffer(); new Thread(){ public void run(){...
public class SyncTest{
public static void main(String[] args){
final StringBuffer s1=new StirngBuffer();
final StringBuffer s2=new StirngBuffer();
new Thread(){
public void run(){
Synchronized(s1){
s1.append("A");
Synchronized(s2){
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread(){
public void run(){
Synchronized(s2){
s2.append("C");
Synchronized(s1){
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
what is the result?
A.the result depends on different system and different thread model
B.the result cannot be determined
--------------------------------
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1];
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4 B. After line 5 C.After line 6
D.After line 7 E.After line 9(that is,as the method returns)
何解,为什么?
public static void main(String[] args){
final StringBuffer s1=new StirngBuffer();
final StringBuffer s2=new StirngBuffer();
new Thread(){
public void run(){
Synchronized(s1){
s1.append("A");
Synchronized(s2){
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread(){
public void run(){
Synchronized(s2){
s2.append("C");
Synchronized(s1){
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
what is the result?
A.the result depends on different system and different thread model
B.the result cannot be determined
--------------------------------
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1];
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4 B. After line 5 C.After line 6
D.After line 7 E.After line 9(that is,as the method returns)
何解,为什么?
|
会被死锁吧!
link:http://www-900.ibm.com/developerWorks/cn/java/praxis/pr52.shtml
link:http://www-900.ibm.com/developerWorks/cn/java/praxis/pr52.shtml
|
这样的考题好象有点太刁难了吧?
哪里找的啊?
哪里找的啊?
|
After line 7
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。