Dúvida Thread - Livro Kathy Sierra  XML
Índice dos Fóruns » Java Básico
Autor Mensagem
Quemicles
Entusiasta Java
[Avatar]

Membro desde: 09/08/2009 09:54:33
Mensagens: 23
Offline

11. Given:




Which of the following pairs of method invocations could NEVER be executing at the same time?
(Choose all that apply.)
A. x.a() in thread1, and x.a() in thread2
B. x.a() in thread1, and x.b() in thread2
C. x.a() in thread1, and y.a() in thread2
D. x.a() in thread1, and y.b() in thread2
E. x.b() in thread1, and x.a() in thread2
F. x.b() in thread1, and x.b() in thread2
G. x.b() in thread1, and y.a() in thread2
H. x.b() in thread1, and y.b() in thread2


Answer:
✓ A, F, and H. A is a right answer because when synchronized instance methods are called
on the same instance, they block each other
. F and H can't happen because synchronized
static methods in the same class block each other, regardless of which instance was used
to call the methods. (An instance is not required to call static methods; only the class.)

X C could happen because synchronized instance methods called on different instances
do not block each other. B, D, E, and G could all happen because instance methods and
static methods lock on different objects, and do not block each other. (Objective 4.3)


Não entendi o porquê de acessos simultâneos bloquearem um ao outro, através do que estudei, quando isso
acontecia elas deveriam fazer fila conforme liberação do lock.

Talvez tenha entendido erro, alguém pode me ajudar ?

Obrigado !

This message was edited 2 times. Last update was at 31/12/2009 16:51:59

sobreira
Thread.start()
[Avatar]

Membro desde: 25/11/2008 12:02:41
Mensagens: 26
Offline

O que você não entendeu foi a pergunta.
Which of the following pairs of method invocations could NEVER be executing at the same time?

Ela se refere aos pares que jamais poderiam ser executados simultâneamente. O método a() está sendo sincronizado na instância do objeto armazenado em x. Portanto se ele já estivesse em execução em uma das Threads a outra teria que aguardar o término da execução antes de prosseguir.

[]s e boa sorte no exame.

This message was edited 1 time. Last update was at 03/01/2010 00:55:10


Fabiano S. Coelho
http://blog.sobreira.eti.br
[WWW]
 
Índice dos Fóruns » Java Básico
Ir para:   
Powered by JForum 2.1.8 © JForum Team