Mais uma de Threads

3 respostas
ricardolecheta

esta é boa para testar uns conceitos.... :D

Consider the following code:
public class Test extends Thread {
	static Object obj = new Object();
	static int x, y;

	public void run() {
		synchronized (obj) {
			for (;;) {
				x++;
				y++;
				System.out.println(x + " " + y);
			}
		}
	}

	public static void main(String[] args) {
		new Test().start();
		new Test().start();
	}
}

What will the above code print?

Select 1 correct option.

A - It will keep on printin same values for x and y incrementing by 1 on each line.

B - It will keep on printin same values for x and y but they may be incrementing by more than 1 on each line.

C - It may print different values for x and y but both the values will be incrementing by 1 on each line.

D - You cannot say anything about the values.

3 Respostas

marciolx

eu acho que é a A, já que as duas variáveis são incrementadas no mesmo loop… é isso?

B

Tambem acho que eh a letra A, pois o primeiro thread a ser startad nao vai perder o foco nunca. (usar teclado sem acento eh horrivel)

ricardolecheta

ambos acertaram :smiley:

Criado 8 de setembro de 2003
Ultima resposta 9 de set. de 2003
Respostas 3
Participantes 3