A voir également:
- Thread runnable ou blocked
- Thread - Accueil - Guide réseaux sociaux
- Compte thread - Accueil - Réseaux sociaux
- This url has been blocked. error code: 4722 - Forum Google Chrome
- System thread exception not handled ndis.sys ✓ - Forum Windows 10
- Sorry, you have been blocked - Forum Discord
2 réponses
KX
Messages postés
16755
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
Modifié par KX le 23/10/2013 à 19:34
Modifié par KX le 23/10/2013 à 19:34
Tu n'as pas de BLOCKED parce que tu n'as pas de verrou, donc tes deux threads cohabitent très bien en parallèle sans se gêner l'un l'autre.
Exemple de blocage :
Exemple de blocage :
import java.util.ArrayList;
public class TestThread extends Thread
{
private static ArrayList<Thread> list = new ArrayList<Thread>();
public TestThread(int n)
{
super("T" + n);
list.add(this);
}
@Override
public void run()
{
action(getName());
}
private static synchronized void action(String name)
{
System.out.println(name + " : START");
try
{
Thread.sleep(100);
log();
}
catch (InterruptedException e)
{
}
System.out.println(name + " : FINISH");
}
private static void log()
{
for (Thread t : list)
System.out.println(t.getName() + " : " + t.getState());
}
public static void main(String[] args) throws InterruptedException
{
for (int i = 1; i <= 3; i++ )
new TestThread(i);
log();
for (Thread t : list)
t.start();
for (Thread t : list)
t.join();
log();
}
}