Class ThreadBasicsExamples

java.lang.Object
net.jrodolfo.java_evolution.java01.ThreadBasicsExamples

public class ThreadBasicsExamples extends Object
Refreshes early Java Thread and Runnable usage.
  • Constructor Details

    • ThreadBasicsExamples

      public ThreadBasicsExamples()
  • Method Details

    • runRunnableInThread

      public int runRunnableInThread() throws InterruptedException
      Runs work in a thread created with a Runnable.
      Returns:
      the value changed by the worker thread
      Throws:
      InterruptedException - when waiting is interrupted
    • synchronizedCounter

      public int synchronizedCounter() throws InterruptedException
      Uses synchronization to protect a shared counter.
      Returns:
      the final counter value
      Throws:
      InterruptedException - when waiting is interrupted