YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -1,23 +1,35 @@
import java.io.IOExeception;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
public class SingletonApp
{
private static final int PORT = 12345; // random large port number
private static ServerSocket s;
private static final int PORT = 65000; // random large port number
private static ServerSocket s;
// static initializer
{
try {
s = new ServerSocket(PORT, 10, InetAddress.getLocalHost());
} catch (UnknownHostException e) {
// shouldn't happen for localhost
} catch (IOException e) {
// port taken, so app is already running
System.exit(0);
}
}
// main() and rest of application...
// static initializer
static {
try {
s = new ServerSocket(PORT, 10, InetAddress.getLocalHost());
} catch (UnknownHostException e) {
// shouldn't happen for localhost
} catch (IOException e) {
// port taken, so app is already running
System.out.print("Application is already running,");
System.out.println(" so terminating this instance.");
System.exit(0);
}
}
public static void main(String[] args) {
System.out.print("OK, only this instance is running");
System.out.println(" but will terminate in 10 seconds.");
try {
Thread.sleep(10000);
if (s != null && !s.isClosed()) s.close();
} catch (Exception e) {
System.err.println(e);
}
}
}