title: java.lang.NoClassDefFoundError: Could not initialize class java.util.Random
body: <pre><code>package com.nodic.test;
  
  import java.util.Random;
  
  public class StopThread {
    private static User user = new User();
  
    public static class User {
      private int id;
      private String name;
  
      public User() {
        id  = 1;
        name = "1";
      }
  
      @Override
      public String toString() {
        return "{id=" + id + ", name=\"" + name + "\"}";
      }
  
      public String getName() {
        return name;
      }
  
      public void setName(String name) {
        this.name = name;
      }
  
      public int getId() {
        return id;
      }
  
      public void setId(int id) {
        this.id = id;
      }
    }
  
    public static class WriteThread implements Runnable {
      @Override
      public void run() {
        while(true) {
          synchronized (user) {
            int curr_id = new Random().nextInt();
  
            user.setId(curr_id);
  
            try {
              Thread.sleep(10000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
  
            user.setName(String.valueOf(curr_id));
          }
  
          Thread.yield();
        }
      }
    }
  
    public static class ReadThread implements Runnable {
      @Override
      public void run() {
        while (true) {
          synchronized (user) {
            if(!user.getName().equals(String.valueOf(user.getId()))) {
              System.out.println(user.toString());
              break;
            }
          }
  
          Thread.yield();
        }
      }
    }
  
    public static void main(String[] args) {
      new Thread(new ReadThread(), "Thread-StopThread-ReadThread").start();
  
      int count = 0;
  
      while(count &lt; 50) {
        Thread t = new Thread(new WriteThread(), "Thread-StopThread-WriteThread");
        t.start();
  
        t.stop();
  
        count ++;
      }
    }
  }
  </code></pre>
  
  <p>HI every one, when i run this class with jdk1.8.0_45, why i always got this error: java.lang.NoClassDefFoundError: Could not initialize class java.util.Random </p>
  
  <blockquote>
    <p>/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java
    -Didea.launcher.port=7534 "-Didea.launcher.bin.path=/Applications/IDE/IntelliJ IDEA /IntelliJ
    IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/huangshiqian/Workspaces/IDEA/Test/concurrent/target/classes:/Users/huangshiqian/.m2/repository/junit/junit/4.9/junit-4.9.jar:/Users/huangshiqian/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar:/Applications/IDE/IntelliJ
    IDEA /IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar"
    com.intellij.rt.execution.application.AppMain
    com.nodic.test.StopThread</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"
    Exception in thread "Thread-StopThread-WriteThread" Exception in
    thread "Thread-StopThread-WriteThread"  Exception:
    java.lang.ThreadDeath thrown from the UncaughtExceptionHandler in
    thread "Thread-StopThread-WriteThread" Exception in thread
    "Thread-StopThread-WriteThread" Exception in thread
    "Thread-StopThread-WriteThread" Exception in thread
    "Thread-StopThread-WriteThread" Exception in thread
    "Thread-StopThread-WriteThread"  Exception: java.lang.ThreadDeath
    thrown from the UncaughtExceptionHandler in thread
    "Thread-StopThread-WriteThread"</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"</p>
    
    <p>Exception: java.lang.ThreadDeath thrown from the
    UncaughtExceptionHandler in thread "Thread-StopThread-WriteThread"
    Exception in thread "Thread-StopThread-WriteThread"
    java.lang.NoClassDefFoundError: Could not initialize class
    java.util.Random  at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)     at
    java.lang.Thread.run(Thread.java:745) Exception in thread
    "Thread-StopThread-WriteThread" java.lang.NoClassDefFoundError: Could
    not initialize class java.util.Random     at
    com.nodic.test.StopThread$WriteThread.run(StopThread.java:44)</p>
  </blockquote>