Tech4um
1 Membres connectés - 1 Visiteurs
Mot de passe oublié?
Espace membre
Faite une inscription rapide sur tech4um.com et participez par vos sujets et commentaires sur nos forums.

Vous bénéficiez aussi de la Discussion directe afin d'avoir des solutions rapide.

Facebook
Twitter
Liens recommandés




C'est quoi votre sujet?

Créer des threads de priorités différentes
Tech4um Postmaster Ajouter le 2011-10-10 01:48:26

Salut,



Vous trouverez ici un programme en Java qui crée des threads de priorités différentes



class ThreadPrio implements Runnable

{

public long count=0;

Thread t;

private volatile boolean running=true;

public ThreadPrio(int p)

{

t=new Thread(this);

t.setPriority(p);

}

public void run()

{

while(running)

count++;

}

public void start()

{

t.start();

}

public void stop()

{

running=false;

}

public static void main(String[] args) throws InterruptedException

{

Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

ThreadPrio t7=new ThreadPrio(7);

ThreadPrio t5=new ThreadPrio(5);

ThreadPrio t3=new ThreadPrio(3);

ThreadPrio t1=new ThreadPrio(1);

t1.start();

t3.start();

t5.start();

t7.start();

System.out.println("Main va être mis en veille pour 10 secs. Patientez svp.");

Thread.sleep(10000);

t1.stop();

t3.stop();

t5.stop();

t7.stop();

t1.t.join();

t3.t.join();

t5.t.join();

t7.t.join();

System.out.println("Thread with Priority 1 :"+t1.count);

System.out.println("Thread with Priority 3 :"+t3.count);

System.out.println("Thread with Priority 5 :"+t5.count);

System.out.println("Thread with Priority 7 :"+t7.count);

} }
Signaler un abus

 

Tech4um Postmaster Ajouter le 2011-10-10 03:18:31

IMPORTANT!

Signaler un abus

[ 1 ]



Répondre au sujet: