Java CyclicBarrier example

An example from the very good Java 8 book “Beginning Java 8 Language Features”. :

 

[Java] util.concurrent.Semaphore example

An example from the very good Java 8 book “Beginning Java 8 Language Features”. :

 

[Java 8] Collection.removeIf() example

 

Simple Java socket server with Executor

And an example with the ExecutorService class:  

 

[HOWTO] Timing multiple threads using CountDownLatch

Here’s an example program which spawns a number of threads of a class and counts the time taken to execute them all. The CountDownLatch may also be used in simulation programs where a JOIN element is needed.

Some details from the Java API:

A synchronization aid that allows one or more threads to…

Java Comparator example

Here’s our class we want to compare. Note the implemented inner classes that implement the Comparator interface:

And here’s the client class:

 

Java Merge Sort

Here is a Java example of Merge Sort algorithm:

And here is the Bootom Up Merge Sort:

 

[java] check password against DB

To check the password against the database encoded value is simple, but it is not supported out of the box. You’ll have to convert the generated hash into hex format [code language=”java”] byte[] encoded = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < encoded.length; i++) { sb.append(Integer.toString((encoded[i] & 0xff) +…

Simple DOM example Java

1. The DOM parser example:

2. The XML file