Background
This post summarises various sorting techniques.
Sorting Techniques
I have written posts over time to show the implementation of some of the sorting techniques. Following are links to the same -
//final field 1 public final transient String myName = "Aniket"; //final field 2 public final transient Logger myLogger = LoggerFactory.getLogger(MyClass.class.getName());
/** * The table, resized as necessary. Length MUST Always be a power of two. */ transient Entry[] table;
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable { private static final long serialVersionUID = 362498820763181265L;
public static void withSemaphores() throws InterruptedException, ExecutionException { Semaphore oddLock = new Semaphore(1); Semaphore evenLock = new Semaphore(0); Runnable printOdd = () -> { for (int i = 1; i < 10; i = i + 2) { try { oddLock.acquire(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } ; System.out.println(i); evenLock.release(); } }; Runnable printEven = () -> { for (int i = 2; i < 10; i = i + 2) { try { evenLock.acquire(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(i); oddLock.release(); } }; new Thread(printOdd).start(); new Thread(printEven).start(); }
public class Test { public static void main(String args[]) throws InterruptedException, ExecutionException { Callable<String> callable = () -> { Thread.sleep(5000); return "Hello!"; }; FutureTask<String> futureTask = new FutureTask<>(callable); Thread t = new Thread(futureTask); t.start(); while (!futureTask.isDone()) { System.out.println("Task not done yet!"); Thread.sleep(1000); } System.out.println(futureTask.get()); } }