コード例 #1
0
        protected internal virtual bool scheduleLongRunningWork(ThreadStart runnable)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.jboss.as.threads.ManagedQueueExecutorService managedQueueExecutorService = managedQueueInjector.getValue();
            ManagedQueueExecutorService managedQueueExecutorService = managedQueueInjector.Value;

            bool rejected = false;

            try
            {
                // wait for 2 seconds for the job to be accepted by the pool.
                managedQueueExecutorService.executeBlocking(runnable, 2, TimeUnit.SECONDS);
            }
            catch (InterruptedException)
            {
                // the acquisition thread is interrupted, this probably means the app server is turning the lights off -> ignore
            }
            catch (ExecutionTimedOutException)
            {
                rejected = true;
            }
            catch (RejectedExecutionException)
            {
                rejected = true;
            }
            catch (Exception e)
            {
                // if it fails for some other reason, log a warning message
                long now = DateTimeHelper.CurrentUnixTimeMillis();
                // only log every 60 seconds to prevent log flooding
                if ((now - lastWarningLogged) >= (60 * 1000))
                {
                    log.log(Level.WARNING, "Unexpected Exception while submitting job to executor pool.", e);
                }
                else
                {
                    log.log(Level.FINE, "Unexpected Exception while submitting job to executor pool.", e);
                }
            }

            return(!rejected);
        }
コード例 #2
0
        protected internal virtual bool scheduleShortRunningWork(ThreadStart runnable)
        {
            ManagedQueueExecutorService managedQueueExecutorService = managedQueueInjector.Value;

            try
            {
                managedQueueExecutorService.executeBlocking(runnable);
                return(true);
            }
            catch (InterruptedException)
            {
                // the the acquisition thread is interrupted, this probably means the app server is turning the lights off -> ignore
            }
            catch (Exception e)
            {
                // we must be able to schedule this
                log.log(Level.WARNING, "Cannot schedule long running work.", e);
            }

            return(false);
        }