Merge branch 'master' into master

This commit is contained in:
Loredana Crusoveanu
2020-06-22 10:58:31 +03:00
committed by GitHub
1928 changed files with 2092 additions and 545323 deletions

View File

@@ -0,0 +1,16 @@
package com.baeldung.thisescape;
public class ImplicitEscape {
public ImplicitEscape() {
Thread t = new Thread() {
@Override
public void run() {
System.out.println("Started...");
}
};
t.start();
}
}

View File

@@ -0,0 +1,14 @@
package com.baeldung.thisescape;
public class LoggerRunnable implements Runnable {
public LoggerRunnable() {
Thread thread = new Thread(this); // this escapes
thread.start();
}
@Override
public void run() {
System.out.println("Started...");
}
}

View File

@@ -0,0 +1,24 @@
package com.baeldung.thisescape;
public class SafePublication implements Runnable {
private final Thread thread;
public SafePublication() {
thread = new Thread(this);
}
@Override
public void run() {
System.out.println("Started...");
}
public void start() {
thread.start();
}
public static void main(String[] args) {
SafePublication publication = new SafePublication();
publication.start();
}
}