Example #1
0
 public URLConnection openConnection() throws IOException {
   final URLConnection con = url.openConnection();
   con.setUseCaches(false);
   con.setConnectTimeout(networkTimeout.intValue(TimeUnit.MILLISECONDS));
   con.setReadTimeout(networkTimeout.intValue(TimeUnit.MILLISECONDS));
   if (headers != null) {
     for (final Entry<String, String> header : headers.entrySet()) {
       con.setRequestProperty(header.getKey(), header.getValue());
     }
   }
   return con;
 }
 private void configure(final String name) {
   /*
    * All executors should be shutdown on application shutdown.
    */
   ShutdownHookManager.register(shutdownHook);
   /*
    * All threads should stop after 60 seconds of idle time
    */
   delegate.setKeepAliveTime(
       FIXED_THREAD_KEEPALIVE_TIMEOUT.longValue(), FIXED_THREAD_KEEPALIVE_TIMEOUT.getTimeUnit());
   /*
    * Fixes non starting with corepoolsize von 0 and not filled queue (Java Conurrency In Practice Chapter 8.3.1).
    * If this bug can occur, a exception would be thrown here.
    */
   delegate.allowCoreThreadTimeOut(true);
   /*
    * Named threads improve debugging.
    */
   delegate.setThreadFactory(new WrappedThreadFactory(name, delegate.getThreadFactory()));
 }
Example #3
0
 public boolean isServerResponding() {
   try {
     final Socket socket = new Socket();
     socket.connect(
         Addresses.asAddress(url.getHost(), url.getPort()),
         networkTimeout.intValue(TimeUnit.MILLISECONDS));
     socket.close();
     return true;
   } catch (final IOException e) {
     return false;
   }
 }