/* package whatever; // don't place package name! */
public class Main {
private static Thread criarThread
( final int numero
) { @Override
public void run( ) {
try {
System .
out .
println ( "t" + numero
+ " começou" ) ; System .
out .
println ( "t" + numero
+ " terminou" ) ; // Ignora...
}
}
} ) ;
}
public static void main
( String [ ] args
) { criarThread( 1 ) ,
criarThread( 2 ) ,
criarThread( 3 ) ,
criarThread( 4 ) ,
criarThread( 5 )
} ;
t.start ( ) ;
}
@Override
public void run( ) {
try {
t.join ( ) ;
// Ignora...
}
}
System .
out .
println ( "Todas as threads terminaram" ) ; }
} ) .start ( ) ;
System .
out .
println ( "A main está livre" ) ; }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKcHVibGljIGNsYXNzIE1haW4gewoKICAgIHByaXZhdGUgc3RhdGljIFRocmVhZCBjcmlhclRocmVhZChmaW5hbCBpbnQgbnVtZXJvKSB7CiAgICAgICAgcmV0dXJuIG5ldyBUaHJlYWQobmV3IFJ1bm5hYmxlKCkgewogICAgICAgICAgICBAT3ZlcnJpZGUKICAgICAgICAgICAgcHVibGljIHZvaWQgcnVuKCkgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oInQiICsgbnVtZXJvICsgIiBjb21lw6dvdSIpOwogICAgICAgICAgICAgICAgICAgIFRocmVhZC5zbGVlcCgoaW50KSAoTWF0aC5yYW5kb20oKSAqIDEwMDAwKSk7CiAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJ0IiArIG51bWVybyArICIgdGVybWlub3UiKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKEludGVycnVwdGVkRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgICAgICAgICAvLyBJZ25vcmEuLi4KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgfQoKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBUaHJlYWRbXSB0cyA9IHsKICAgICAgICAgICAgY3JpYXJUaHJlYWQoMSksCiAgICAgICAgICAgIGNyaWFyVGhyZWFkKDIpLAogICAgICAgICAgICBjcmlhclRocmVhZCgzKSwKICAgICAgICAgICAgY3JpYXJUaHJlYWQoNCksCiAgICAgICAgICAgIGNyaWFyVGhyZWFkKDUpCiAgICAgICAgfTsKICAgICAgICBmb3IgKFRocmVhZCB0IDogdHMpIHsKICAgICAgICAgICAgdC5zdGFydCgpOwogICAgICAgIH0KCiAgICAgICAgbmV3IFRocmVhZChuZXcgUnVubmFibGUoKSB7CiAgICAgICAgICAgIEBPdmVycmlkZQogICAgICAgICAgICBwdWJsaWMgdm9pZCBydW4oKSB7CiAgICAgICAgICAgICAgICBmb3IgKFRocmVhZCB0IDogdHMpIHsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICB0LmpvaW4oKTsKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChJbnRlcnJ1cHRlZEV4Y2VwdGlvbiBlKSB7CiAgICAgICAgICAgICAgICAvLyBJZ25vcmEuLi4KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRvZGFzIGFzIHRocmVhZHMgdGVybWluYXJhbSIpOwogICAgICAgICAgICB9CiAgICAgICAgfSkuc3RhcnQoKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkEgbWFpbiBlc3TDoSBsaXZyZSIpOwoJfQp9