Last active
March 30, 2016 12:31
-
-
Save IlyaHalsky/7debac304f76668503f2102920529135 to your computer and use it in GitHub Desktop.
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.io.*; | |
import java.util.StringTokenizer; | |
/** | |
* Created by Ilya239 on 29.03.2016. | |
*/ | |
public class FastScanner { | |
BufferedReader br; | |
StringTokenizer st; | |
FastScanner(File f) { | |
try { | |
br = new BufferedReader(new FileReader(f)); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
FastScanner() { | |
br = new BufferedReader(new InputStreamReader(System.in)); | |
} | |
String next() { | |
while (st == null || !st.hasMoreTokens()) { | |
try { | |
st = new StringTokenizer(br.readLine()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
return st.nextToken(); | |
} | |
int nextInt() { | |
return Integer.parseInt(next()); | |
} | |
} |
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.io.*; | |
import java.lang.management.ManagementFactory; | |
import java.util.StringTokenizer; | |
/** | |
* Created by Ilya239 on 29.03.2016. | |
*/ | |
public class Looper implements Runnable{ | |
static FastScanner in; | |
int i = 0; | |
volatile boolean done = false; | |
@Override | |
public void run() { | |
while (!done) { | |
i++; | |
if (Thread.currentThread().isInterrupted()) { | |
done = true; | |
i = 0; | |
} | |
} | |
} | |
public static void main(String args[]) { | |
int n = 3; | |
try { | |
in = new FastScanner(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
Thread[] threads = new Thread[n]; | |
for (int i = 0; i < n; i++) { | |
threads[i] = new Thread(new Looper()); | |
threads[i].start(); | |
} | |
System.out.println(Integer.parseInt(ManagementFactory.getRuntimeMXBean().getName().toString().substring(0,ManagementFactory.getRuntimeMXBean().getName().indexOf('@')))); | |
try { | |
PrintStream ps = new PrintStream("pid.txt"); | |
ps.println(ManagementFactory.getRuntimeMXBean().getName().toString().substring(0,ManagementFactory.getRuntimeMXBean().getName().indexOf('@'))); | |
ps.flush(); | |
ps.close(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
in.next(); | |
for (int i = 0; i < n; i++) { | |
threads[i].interrupt(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment