title: Synchronized keyword Java speed effienciency
body: <p><strong>Feel free to correct me if I am wrong!</strong> </p>
  
  <p>The synchronized keyword in java makes a method unable to be run be different threads simultaneously. In my program I have 4 different threads that run on the same time counting to 100.000.</p>
  
  <p>When adding the synchronized keyword to the method being performed, it should take four times the amount of time as it would multithreading?</p>
  
  <p>Executing the programs either way, takes roughly 16 seconds. </p>
  
  <p>Heres my code!</p>
  
  <pre><code>public class ExerciseThree {
  
      public static void main(String[] args) {
          Even even = new Even();
          Thread t1 = new Thread(() -&gt; {
              for (int i = 0; i &lt; 100000; i++) {
                  System.out.println(even.next());
              }
          });
          Thread t2 = new Thread(() -&gt; {
              for (int i = 0; i &lt; 100000; i++) {
                  System.out.println(even.next());
              }
          });
          Thread t3 = new Thread(() -&gt; {
              for (int i = 0; i &lt; 100000; i++) {
                  System.out.println(even.next());
              }
          });
          Thread t4 = new Thread(() -&gt; {
              for (int i = 0; i &lt; 100000; i++) {
                  System.out.println(even.next());
              }
          });
          System.out.println("starting thread 1");
          t1.start();
          System.out.println("starting thread 2");
          t2.start();
          System.out.println("starting thread 3");
          t3.start();
          System.out.println("starting thread 4");
          t4.start();
      }
  }
  </code></pre>
  
  <p>The method being called by the threads</p>
  
  <pre><code>public class Even {
  
          private int n = 0;
  
  //      public synchronized int next() {
          public int next() {
              n++;
              n++;
              return n;
          }
      }
  </code></pre>