Created
June 9, 2018 17:47
-
-
Save paullewallencom/c146da9c54c219ade29483e027714f68 to your computer and use it in GitHub Desktop.
Waiting for the Finalization of a Thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
import java.util.concurrent.TimeUnit; | |
public class DataSourcesLoader implements Runnable { | |
@Override | |
public void run() { | |
// Writes a messsage | |
System.out.printf("Begining data sources loading: %s\n",new Date()); | |
// Sleeps four seconds | |
try { | |
TimeUnit.SECONDS.sleep(4); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
// Writes a message | |
System.out.printf("Data sources loading has finished: %s\n",new Date()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Waiting for the finalization of a thread | |
import java.util.Date; | |
public class Main { | |
public static void main(String[] args) { | |
// Creates and starts a DataSourceLoader runnable object | |
DataSourcesLoader dsLoader = new DataSourcesLoader(); | |
Thread thread1 = new Thread(dsLoader,"DataSourceThread"); | |
// Creates and starts a NetworkConnectionsLoader runnable object | |
NetworkConnectionsLoader ncLoader = new NetworkConnectionsLoader(); | |
Thread thread2 = new Thread(ncLoader,"NetworkConnectionLoader"); | |
// Start both threads | |
thread1.start(); | |
thread2.start(); | |
// Wait for the finalization of the two threads | |
try { | |
thread1.join(); | |
thread2.join(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
// Waits a message | |
System.out.printf("Main: Configuration has been loaded: %s\n",new Date()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
import java.util.concurrent.TimeUnit; | |
public class NetworkConnectionsLoader implements Runnable { | |
@Override | |
public void run() { | |
// Writes a message | |
System.out.printf("Begining network connections loading: %s\n",new Date()); | |
// Sleep six seconds | |
try { | |
TimeUnit.SECONDS.sleep(6); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
// Writes a message | |
System.out.printf("Network connections loading has finished: %s\n",new Date()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment