vertx.executeBlocking(promise -> { // Call some blocking API that takes a significant amount of time to return String result = someAPI.blockingMethod("hello"); promise.complete(result); }, res -> { System.out.println("The result is: " + res.result()); });
作为代理最核心的功能就是转发钉钉的回调消息,前面我说到,Event Bus 在 Vertx 中起到了“神经系统的作用”实际上 ,换句话说,就是http 服务收到回调的时候,可以通过 Event Bus 发出消息。WebSocket 在收到 Event Bus 发来的消息的时候,推送给客户端。如下图看图:
publicabstractclassClassLoader { // The parent class loader for delegation // Note: VM hardcoded the offset of this field, thus all new fields // must be added *after* it. privatefinal ClassLoader parent;
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) { // 尝试使用 父辈的 loadClass 方法 c = parent.loadClass(name, false); } else { // 如果没有 父辈的 classLoader 就使用 bootstrap classLoader 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(); // 父辈没法加载这个 class,就自己尝试加载 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; } }
@Override public Class<?> findClass(String name) throws ClassNotFoundException { // Ask our superclass to locate this class, if possible // (throws ClassNotFoundException if it is not found) Class<?> clazz = null;
// 先在自己的 Web 应用目录下查找 class clazz = findClassInternal(name);