List of usage examples for java.lang ThreadDeath ThreadDeath
ThreadDeath
From source file:com.google.acre.script.HostEnv.java
@SuppressWarnings("null") @JSFunction// ww w. java 2 s.c o m public String dev_test_internal(String name) { // the js entry point shouldn't be visible to user scripts // unless developer mode is enabled, but double-check it // here too. if (!ACRE_DEVELOPER_MODE) { return ""; } if (name.equals("OutOfMemoryError")) { throw new OutOfMemoryError("this is an OutOfMemoryError message"); } if (name.equals("StackOverflowError")) { throw new StackOverflowError("this is an StackOverflowError message"); } if (name.equals("ThreadDeath")) { throw new ThreadDeath(); } if (name.equals("RuntimeException")) { throw new RuntimeException("this is a RuntimeException message"); } if (name.equals("Error")) { throw new Error("this is an Error message"); } if (name.equals("AcreScriptError")) { throw new AcreScriptError("AcreScriptError - faked script was taking too long"); } if (name.equals("NullPointerException")) { Object n = null; n.toString(); } // not really "throw", so the different naming style is deliberate if (name.equals("java_infinite_loop")) { boolean a = true; while (a) { } } // quick-and-dirty reflecton of options to this function // so they aren't duplicated in test code if (name.equals("list")) { return "OutOfMemoryError StackOverflowError ThreadDeath RuntimeException Error AcreScriptError NullPointerException java_infinite_loop"; } // TODO add more options to test potential java failures // log_spew to try to overwhelm the log system // ... // if you add more cases, update the "list" case above too! return ""; }
From source file:com.globalsight.webservices.Ambassador.java
/** * Updates a tu in database./* w w w .j ava 2s . c om*/ * * @param accessToken * To judge caller has logon or not, can not be null. you can get * it by calling method <code>login(username, password)</code>. * @param tmName * TM name, will used to get tm id. * @param companyName * company name, will used to get tm id. * @param tmx * A tmx formate string inlcluding all tu information. * @return "true" if succeed * @throws WebServiceException */ public String editTu(String accessToken, String tmName, String companyName, String tmx) throws WebServiceException { try { Assert.assertNotEmpty(accessToken, "access token"); Assert.assertNotEmpty(tmx, "tmx format"); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebServiceException(e.getMessage()); } checkAccess(accessToken, "editEntry"); checkPermission(accessToken, Permission.TM_EDIT_ENTRY); Company company = getCompanyByName(companyName); if (company == null) { throw new WebServiceException("Can not find the company with name (" + companyName + ")"); } final ProjectTM ptm = getProjectTm(tmName, company.getIdAsLong()); if (ptm == null) { throw new WebServiceException( "Can not find the tm with tm name (" + tmName + ") and company name (" + companyName + ")"); } SAXReader reader = new SAXReader(); ElementHandler handler = new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element element = path.getCurrent(); element.detach(); try { normalizeTu(element); validateTu(element); if (ptm.getTm3Id() == null) { editTm2Tu(element); } else { editTm3Tu(element, ptm); } } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new ThreadDeath(); } } }; reader.addHandler("/tu", handler); WebServicesLog.Start activityStart = null; try { String loggedUserName = this.getUsernameFromSession(accessToken); Map<Object, Object> activityArgs = new HashMap<Object, Object>(); activityArgs.put("loggedUserName", loggedUserName); activityStart = WebServicesLog.start(Ambassador.class, "editTu(accessToken,tmx)", activityArgs); reader.read(new StringReader(tmx)); } catch (DocumentException e) { logger.error(e.getMessage(), e); throw new WebServiceException(e.getMessage()); } finally { if (activityStart != null) { activityStart.end(); } } return "true"; }
From source file:org.apache.catalina.loader.WebappClassLoader.java
/** * Load the class with the specified name, searching using the following * algorithm until it finds and returns the class. If the class cannot * be found, returns <code>ClassNotFoundException</code>. * <ul>/*from ww w. j a v a2 s. c o m*/ * <li>Call <code>findLoadedClass(String)</code> to check if the * class has already been loaded. If it has, the same * <code>Class</code> object is returned.</li> * <li>If the <code>delegate</code> property is set to <code>true</code>, * call the <code>loadClass()</code> method of the parent class * loader, if any.</li> * <li>Call <code>findClass()</code> to find this class in our locally * defined repositories.</li> * <li>Call the <code>loadClass()</code> method of our parent * class loader, if any.</li> * </ul> * If the class was found using the above steps, and the * <code>resolve</code> flag is <code>true</code>, this method will then * call <code>resolveClass(Class)</code> on the resulting Class object. * * @param name Name of the class to be loaded * @param resolve If <code>true</code> then resolve the class * * @exception ClassNotFoundException if the class was not found */ public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (log.isDebugEnabled()) log.debug("loadClass(" + name + ", " + resolve + ")"); Class clazz = null; // Don't load classes if class loader is stopped if (!started) { log.info(sm.getString("webappClassLoader.stopped")); throw new ThreadDeath(); } // (0) Check our previously loaded local class cache clazz = findLoadedClass0(name); if (clazz != null) { if (log.isDebugEnabled()) log.debug(" Returning class from cache"); if (resolve) resolveClass(clazz); return (clazz); } // (0.1) Check our previously loaded class cache clazz = findLoadedClass(name); if (clazz != null) { if (log.isDebugEnabled()) log.debug(" Returning class from cache"); if (resolve) resolveClass(clazz); return (clazz); } // (0.2) Try loading the class with the system class loader, to prevent // the webapp from overriding J2SE classes // GOOGLE: use the bootstrap loader, not the system loader; it breaks // embedding. try { // clazz = system.loadClass(name); clazz = Class.forName(name, false, null); if (clazz != null) { if (resolve) resolveClass(clazz); return (clazz); } } catch (ClassNotFoundException e) { // Ignore } // (0.5) Permission to access this class when using a SecurityManager if (securityManager != null) { int i = name.lastIndexOf('.'); if (i >= 0) { try { securityManager.checkPackageAccess(name.substring(0, i)); } catch (SecurityException se) { String error = "Security Violation, attempt to use " + "Restricted Class: " + name; log.info(error, se); throw new ClassNotFoundException(error, se); } } } boolean delegateLoad = delegate || filter(name); // (1) Delegate to our parent if requested if (delegateLoad) { if (log.isDebugEnabled()) log.debug(" Delegating to parent classloader1 " + parent); ClassLoader loader = parent; if (loader == null) loader = system; try { clazz = loader.loadClass(name); if (clazz != null) { if (log.isDebugEnabled()) log.debug(" Loading class from parent"); if (resolve) resolveClass(clazz); return (clazz); } } catch (ClassNotFoundException e) { ; } } // (2) Search local repositories if (log.isDebugEnabled()) log.debug(" Searching local repositories"); try { clazz = findClass(name); if (clazz != null) { if (log.isDebugEnabled()) log.debug(" Loading class from local repository"); if (resolve) resolveClass(clazz); return (clazz); } } catch (ClassNotFoundException e) { ; } // (3) Delegate to parent unconditionally if (!delegateLoad) { if (log.isDebugEnabled()) log.debug(" Delegating to parent classloader at end: " + parent); ClassLoader loader = parent; if (loader == null) loader = system; try { clazz = loader.loadClass(name); if (clazz != null) { if (log.isDebugEnabled()) log.debug(" Loading class from parent"); if (resolve) resolveClass(clazz); return (clazz); } } catch (ClassNotFoundException e) { ; } } throw new ClassNotFoundException(name); }
From source file:org.apache.tomcat.util.net.PoolTcpEndpoint.java
Socket acceptSocket() { if (!running || serverSocket == null) return null; Socket accepted = null;/*w w w. j a v a2 s. co m*/ try { if (factory == null) { accepted = serverSocket.accept(); } else { accepted = factory.acceptSocket(serverSocket); } if (null == accepted) { log.warn("Null socket returned by accept"); } else { if (!running) { accepted.close(); // rude, but unlikely! accepted = null; } else if (factory != null) { factory.initSocket(accepted); } } } catch (InterruptedIOException iioe) { // normal part -- should happen regularly so // that the endpoint can release if the server // is shutdown. } catch (AccessControlException ace) { // When using the Java SecurityManager this exception // can be thrown if you are restricting access to the // socket with SocketPermission's. // Log the unauthorized access and continue String msg = sm.getString("endpoint.warn.security", serverSocket, ace); log.warn(msg); } catch (IOException e) { String msg = null; if (running) { msg = sm.getString("endpoint.err.nonfatal", serverSocket, e); log.error(msg, e); } if (accepted != null) { try { accepted.close(); } catch (Throwable ex) { msg = sm.getString("endpoint.err.nonfatal", accepted, ex); log.warn(msg, ex); } accepted = null; } if (!running) return null; reinitializing = true; // Restart endpoint when getting an IOException during accept synchronized (threadSync) { if (reinitializing) { reinitializing = false; // 1) Attempt to close server socket closeServerSocket(); initialized = false; // 2) Reinit endpoint (recreate server socket) try { msg = sm.getString("endpoint.warn.reinit"); log.warn(msg); initEndpoint(); } catch (Throwable t) { msg = sm.getString("endpoint.err.nonfatal", serverSocket, t); log.error(msg, t); } // 3) If failed, attempt to restart endpoint if (!initialized) { msg = sm.getString("endpoint.warn.restart"); log.warn(msg); try { stopEndpoint(); initEndpoint(); startEndpoint(); } catch (Throwable t) { msg = sm.getString("endpoint.err.fatal", serverSocket, t); log.error(msg, t); } finally { // Current thread is now invalid: kill it throw new ThreadDeath(); } } } } } return accepted; }