Skip to content

Instantly share code, notes, and snippets.

@hdelei
Created March 23, 2023 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdelei/93a03769f7d3be648328b48d717f9f65 to your computer and use it in GitHub Desktop.
Save hdelei/93a03769f7d3be648328b48d717f9f65 to your computer and use it in GitHub Desktop.
class ClasseThread extends Thread{
String descricaoClasse;
public ClasseThread(String descricao){
descricaoClasse = descricao;
}
public void run(){
int soma = 0;
for (int i = 0; i < 100; i++){
soma += i;
System.out.println( descricaoClasse + ": somando os números de 1 a 100 é igual : " + soma);
}
}
}
public class ExemploThread {
public static void main(String[] args) {
//Criando uma nova thread dentro do prog...
ClasseThread ta = new ClasseThread("Classe 1");
ClasseThread tb = new ClasseThread("Classe 2");
tb.start();
ta.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment