protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { synchronized (getClassLoadingLock(name)) { // First, check if the class has already been loaded Class<?> c = findLoadedClass(name); if (c == null) { longt0= System.nanoTime(); try { if (parent != null) { c = parent.loadClass(name, false); } else { c = findBootstrapClassOrNull(name); } } catch (ClassNotFoundException e) { // ClassNotFoundException thrown if class not found // from the non-null parent class loader }
if (c == null) { // If still not found, then invoke findClass in order // to find the class. longt1= System.nanoTime(); c = findClass(name); // this is the defining class loader; record the stats sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); sun.misc.PerfCounter.getFindClasses().increment(); } } if (resolve) { resolveClass(c); } return c; } }
/** * Appends the specified element to the end of this list. * * @param e element to be appended to this list * @return {@code true} (as specified by {@link Collection#add}) */ publicbooleanadd(E e) { //获取写锁 finalReentrantLocklock=this.lock; lock.lock(); try { // 获取真正的资源 Object[] elements = getArray(); intlen= elements.length; // 复制一份私有副本 Object[] newElements = Arrays.copyOf(elements, len + 1); // 修改私有副本 newElements[len] = e; // 私有副本修改完毕之后,替代真正的资源 setArray(newElements); returntrue; } finally { lock.unlock(); } }
/** * Sets the array. */ finalvoidsetArray(Object[] a) { array = a; }
Whenever Redis needs to dump the dataset to disk, this is what happens: Redis forks. We now have a child and a parent process. The child starts to write the dataset to a temporary RDB file. When the child is done writing the new RDB file, it replaces the old one. This method allows Redis to benefit from copy-on-write semantics.