YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
# Project : Determine if only one instance is running
|
||||
|
||||
task = "ringw.exe"
|
||||
taskname = "tasklist.txt"
|
||||
remove(taskname)
|
||||
system("tasklist >> tasklist.txt")
|
||||
fp = fopen(taskname,"r")
|
||||
tasks = read("tasklist.txt")
|
||||
counttask = count(tasks,task)
|
||||
if counttask > 0
|
||||
see task + " running in " + counttask + " instances" + nl
|
||||
else
|
||||
see task + " is not running" + nl
|
||||
ok
|
||||
|
||||
func count(cString,dString)
|
||||
sum = 0
|
||||
while substr(cString,dString) > 0
|
||||
sum++
|
||||
cString = substr(cString,substr(cString,dString)+len(string(sum)))
|
||||
end
|
||||
return sum
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import java.io.IOException
|
||||
import java.net.{InetAddress, ServerSocket}
|
||||
|
||||
object SingletonApp extends App {
|
||||
private val port = 65000
|
||||
|
||||
try {
|
||||
val s = new ServerSocket(port, 10, InetAddress.getLocalHost)
|
||||
}
|
||||
catch {
|
||||
case _: IOException =>
|
||||
// port taken, so app is already running
|
||||
println("Application is already running, so terminating this instance.")
|
||||
sys.exit(-1)
|
||||
}
|
||||
|
||||
println("OK, only this instance is running but will terminate in 10 seconds.")
|
||||
|
||||
Thread.sleep(10000)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue