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
StringBuffer buffer = new StringBuffer(); | |
for (URL url : ((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs()) { | |
buffer.append(new File(url.getPath())); | |
buffer.append(System.getProperty("path.separator")); | |
} | |
String classpath = buffer.toString(); | |
int toIndex = classpath.lastIndexOf(System.getProperty("path.separator")); | |
classpath = classpath.substring(0, toIndex); |
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
ProcessBuilder builder = new ProcessBuilder("java", "-classpath", classpath, "com.a.b.c.TestProgram", "hello", "world"); | |
// java -classpath [classpath] com.a.b.c.TestProgram hello world | |
Process process = builder.start(); | |
// Process is now running. | |
// Block until the process terminates, and then get its exit value. | |
int exitValue = process.waitFor(); |
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
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | |
private final ExecutorService executor = Executors.newFixedThreadPool(1); | |
private final Set<String> serialsSet = new HashSet<String>(); | |
private static final int NUM_SECONDS = 3; | |
// ... | |
private void scheduleTask(final String serial) { | |
// Assume this method is called from a thread in executor. | |
if (!this.serialsSet.contains(serial)) { |
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
// ... | |
if (!this.serialsSet.contains(serial)) { // if (!flag) { | |
this.serialsSet.add(serial); // flag = true; | |
Runnable task = new Runnable() { | |
/** {@inheritDoc} */ | |
@Override | |
public void run() { | |
// Use try-finally. Before the thread dies, it will reset the boolean variable. | |
try { |
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
public void setDate(Date date) { | |
if (date == null) { | |
throw new IllegalArgumentException("date is null"); | |
} | |
this.date = new Date(date.getTime()); | |
} |
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
private static final int NUM_ITERATIONS = 100; | |
// ... | |
System.out.println("Warming up..."); | |
for (int i = 1; i <= NUM_ITERATIONS; i++) { | |
for (Node node : nodes) { | |
Band<Float> band = createBand(Float.class); | |
Random random = new Random(); | |
statsMap.put(band, new Stats(band, random.nextInt(200), |
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
public class ExampleClientService implements ExampleListener { | |
private final List<ExampleListener> listeners = new ArrayList<ExampleListener>(); | |
private final List<Example> examples = new ArrayList<Example>(); | |
public void addExampleListener(ExampleListener listener) { | |
listeners.add(listener); | |
} | |
public void removeExampleListener(ExampleListener listener) { |
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
ExampleListener listener = new ExampleListener(); | |
ExampleClientService service = new ExampleClientService(); | |
service.addExampleListener(listener); |
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
public class ExampleClientService { | |
private final List<ExampleListener> listeners = new ArrayList<ExampleListener>(); | |
private final List<Example> examples = new ArrayList<Example>(); | |
private final ExampleListenerImpl listener = new ExampleListenerImpl(); | |
public ExampleClientService(ExamplesManager examplesManager) { | |
examplesManager.addExampleListener(this.listener); | |
} |
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
public class StudentId implements Serializable { | |
} | |
public class InstructorId implements Serializable { | |
} |
OlderNewer