• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread problem?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. public class SyncTest{
2. public static void main(String[] args)}
3.����final StringBuffer s1=new StringBuffer();
4.����final StringBuffer s2=new StringBuffer();
5.����new Thread() {
6.������ public void run(){
7.���������� synchronized(s1){
8������������������ s1.append(��A��);
9���������������� Synchronized(s2){
10�������������������� s2.append(��B��);
11���������������� System.out.print(s1);
12���������������� System.out.print(s1);
13���������������� }
14������������}
15����������}
16������ }.start();
17���� new Thread(){
18��������public void run(){
19.������������Synchronized(s2){
20.���������������� s2.append(��c��);
21.���� Synchronized(s1){
22.�������� s1.append(��D��);
23.�������� System.out.println(s2);
24.�������� System.out.println(s1);
25.�������� }
26.����}
27.�� }
28. }.start();
29.��}
30. }
thread question without syncronized keyword(choose 2)
a) the program prints ��ABBCAD��
b) the program prints ��CDDACB��
c) the program prints ��ADCBADBC��
d) the output is non-deterministic point because of a possible deadlock
e)the output is dependent on the threading model of the system that the program is running on
what's the anser? thx u!
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say that atleast d is correct. Probably e too.
/Mike
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think choice d and e are correct
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
d and e are the correct answers
 
wei chen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i see,thank a lot!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I executed it and gives the the o/p
ABBCAD i.e b) option.
Can anybody elaborate what will be the other option,and why?
Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic