Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

thread Exemple

/** Premier test de classe de thread en utilisant la
 *  technique qui consiste à dériver de la classe Thread.
 */
public class FirstThread extends Thread {
    /** Un attribut propre à chaque thread */
    private String threadName;
    
    /** Création et démarrage automatique du thread */
    public FirstThread(String threadName) {
        this.threadName = threadName;
        this.start();
    }

    /** Le but d'un tel thread est d'afficher 500 fois
     *  son attribut threadName. Notons que la méthode
     *  <I>sleep</I> peut déclancher des exceptions.
     */
    public void run() {
        try {
            for(int i=0;i<500;i++) {
                System.out.println(
                    "Thread nommé : " + this.threadName +
                    " - itération : " + i
                );
                Thread.sleep(30);  
            }
        } catch (InterruptedException exc) {
            exc.printStackTrace();
        }
    }
 
    /** Le point de démarrage de votre programme.
     *  Notez bien que nous lançons deux threads et que
     *  chacun  d'eux possède une données qui lui est
     *  propre.
     */
    static public void main(String argv[]) {
        FirstThread thr1 = new FirstThread("Toto");
        FirstThread thr2 = new FirstThread("Tata");
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: android studio cannot resolve @nullable 
Java :: what is void in java 
Java :: python to java convert online 
Java :: java output formatting 
Java :: equality primitives java 
Java :: access modifier overloaded method 
Java :: pioneer meaning 
Java :: struct in java 
Java :: fill two dimension array java 
Java :: constructor overloading ambiguity resolved 
Java :: Example of "this" : to invoke current class method 
Java :: concludes() Method 
Java :: Copying Arrays Using arraycopy() method Java 
Java :: convert kotlin to java online 
Java :: interface in java 
Java :: java digit in number 
Java :: java check if class is subclass 
Java :: multiple string java 
Java :: connecting to h2 database from java 
Java :: types of classes in java 
Java :: java format double no decimal places 
Java :: Leap year or not program in java using if-else 
Java :: save text in edditext java 
Java :: spring amqp exchange not found 
Sql :: mysql create user with mysql_native_password 
Sql :: convert utc to est sql 
Sql :: mysql_secure_installation 
Sql :: show host mysql 
Sql :: Cannot load driver class: com.mysql.cj.jdbc.Driver 
Sql :: postgresql Insufficient privilege: 7 ERROR: permission denied for table 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =