Example usage for java.lang Thread NORM_PRIORITY

List of usage examples for java.lang Thread NORM_PRIORITY

Introduction

In this page you can find the example usage for java.lang Thread NORM_PRIORITY.

Prototype

int NORM_PRIORITY

To view the source code for java.lang Thread NORM_PRIORITY.

Click Source Link

Document

The default priority that is assigned to a thread.

Usage

From source file:com.fd.colac.activity.picture.ImagePagerActivity.java

public void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them,
    // or you can create default configuration by
    //  ImageLoaderConfiguration.createDefault(this);
    // method./* ww w  .  j a v a 2s  .c  om*/
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() // Remove for release app
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
}

From source file:org.kineticsystem.commons.data.view.actions.MoveBackMouseAction.java

/**
 * This method is called when the user press a mouse button on the button
 * connected to this action./*from ww w  . j a  v  a  2  s .co m*/
 * @param event The mouse event.
 */
public void mousePressed(MouseEvent event) {

    if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {

        mover = new Accelerator() {

            public void execute() {

                if (navigator.isMoveBackEnabled()) {
                    try {
                        EventQueue.invokeAndWait(new Runnable() {
                            public void run() {
                                navigator.moveBack();
                            }
                        });
                    } catch (Exception ex) {
                        logger.info(ex);
                    }
                } else {
                    interrupt();
                }
            }
        };
        mover.setPriority(Thread.NORM_PRIORITY);
        mover.start();
    }
}

From source file:org.kineticsystem.commons.data.view.actions.MoveForwardMouseAction.java

/**
 * This method is called when the user press a mouse button on the button
 * connected to this action./*w  w w. j  a v  a 2  s  .  c o m*/
 * @param event The mouse event.
 */
public void mousePressed(MouseEvent event) {

    if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {

        mover = new Accelerator() {

            public void execute() {

                if (navigator.isMoveForwardEnabled()) {
                    try {
                        EventQueue.invokeAndWait(new Runnable() {
                            public void run() {
                                navigator.moveNext();
                            }
                        });
                    } catch (Exception ex) {
                        logger.info(ex);
                    }
                } else {
                    interrupt();
                }
            }
        };
        mover.setPriority(Thread.NORM_PRIORITY);
        mover.start();
    }
}

From source file:it.geosolutions.tools.io.file.FileRemover.java

/**
 * Default constructor for a {@link FileRemover}.
 */
public FileRemover() {
    this(Conf.DEFAULT_PERIOD, Thread.NORM_PRIORITY - 3, Conf.DEF_MAX_ATTEMPTS);
}

From source file:org.apache.roller.weblogger.business.runnable.ThreadManagerImpl.java

public void initialize() throws InitializationException {

    // initialize tasks, making sure that each task has a tasklock record in the db
    List<RollerTask> webloggerTasks = new ArrayList<RollerTask>();
    String tasksStr = WebloggerConfig.getProperty("tasks.enabled");
    String[] tasks = StringUtils.stripAll(StringUtils.split(tasksStr, ","));
    for (String taskName : tasks) {

        String taskClassName = WebloggerConfig.getProperty("tasks." + taskName + ".class");
        if (taskClassName != null) {
            log.info("Initializing task: " + taskName);

            try {
                Class taskClass = Class.forName(taskClassName);
                RollerTask task = (RollerTask) taskClass.newInstance();
                task.init(taskName);//from  w  w w  .jav a 2s. c  o m

                // make sure there is a tasklock record in the db
                TaskLock taskLock = getTaskLockByName(task.getName());
                if (taskLock == null) {
                    log.debug("Task record does not exist, inserting empty record to start with");

                    // insert an empty record
                    taskLock = new TaskLock();
                    taskLock.setName(task.getName());
                    taskLock.setLastRun(new Date(0));
                    taskLock.setTimeAquired(new Date(0));
                    taskLock.setTimeLeased(0);

                    // save it
                    this.saveTaskLock(taskLock);
                }

                // add it to the list of configured tasks
                webloggerTasks.add(task);

            } catch (ClassCastException ex) {
                log.warn("Task does not extend RollerTask class", ex);
            } catch (WebloggerException ex) {
                log.error("Error scheduling task", ex);
            } catch (Exception ex) {
                log.error("Error instantiating task", ex);
            }
        }
    }

    // create scheduler
    TaskScheduler scheduler = new TaskScheduler(webloggerTasks);

    // start scheduler thread, but only if it's not already running
    if (schedulerThread == null && scheduler != null) {
        log.debug("Starting scheduler thread");
        schedulerThread = new Thread(scheduler, "Roller Weblogger Task Scheduler");
        // set thread priority between MAX and NORM so we get slightly preferential treatment
        schedulerThread.setPriority((Thread.MAX_PRIORITY + Thread.NORM_PRIORITY) / 2);
        schedulerThread.start();
    }
}

From source file:cn.jasonlv.siri.activity.MainActivity.java

public static void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them,
    // or you can create default configuration by
    // ImageLoaderConfiguration.createDefault(this);
    // method.//from   www  .  j a  v a  2s  .  c  o  m
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for release app

    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}

From source file:net.NettyEngine3.core.NServerFrameNettyStart.java

/**
 * createServerBootstrap will create a pipeline factory and save it as a
 * class variable. This method can then be used to retrieve that value.
 *
 * @return Returns the channel pipeline factory that is associated with this
 *         netty server.//from  ww w.j  a  v a2s. co  m
 *
 *   ExecutionHandler?????handler
 *   worker?ExecutionHandler??
 *   ChannelFactoryworker
 *   ??
 *   ???
 *   executionHandlerThread will be executed the task of {@link com.dc.gameserver.ExtComponents.NettyEngine3.service.HandleController}  it's runnable
 */
@Override
public ChannelPipelineFactory getPipelineFactory() {
    //??bufobjectSession  maxChannelMemorySize maxTotalMemorySize
    //disabled the value of code 0;
    // Deadlock can happen when MemoryAwareThreadPoolExecutor with limit is used
    // fixed by netty 3.6.6.final
    executionHandler = new ExecutionHandler(
            new MemoryAwareThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, 0, 0, 0,
                    TimeUnit.SECONDS, new PriorityThreadFactory("logic_handle", Thread.NORM_PRIORITY + 1)));
    ChannelHandler idleStateHandler = new IdleStateHandler(NServerFrameUtil.timer, 10, 0, 0, TimeUnit.SECONDS);
    return new NServerFrameChannelPipelineFactory(idleStateHandler, executionHandler);
}

From source file:org.jumpmind.symmetric.service.impl.PushService.java

public void start() {
    nodeChannelExtractForPushWorker = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() {
        final AtomicInteger threadNumber = new AtomicInteger(1);
        final String namePrefix = parameterService.getEngineName().toLowerCase() + "-extract-for-push-";

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(namePrefix + threadNumber.getAndIncrement());
            t.setDaemon(false);//from w w  w . ja v a 2s  .  c  om
            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }
            return t;
        }
    });

    nodeChannelTransportForPushWorker = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() {
        final AtomicInteger threadNumber = new AtomicInteger(1);
        final String namePrefix = parameterService.getEngineName().toLowerCase() + "-push-";

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(namePrefix + threadNumber.getAndIncrement());
            t.setDaemon(false);
            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }
            return t;
        }
    });
}

From source file:org.mule.providers.AbstractMessageReceiver.java

/**
 * Creates the Message Receiver//from  www  .j  a v a 2 s.co m
 * 
 * @param connector
 *            the endpoint that created this listener
 * @param component
 *            the component to associate with the receiver. When data is
 *            recieved the component <code>dispatchEvent</code> or
 *            <code>sendEvent</code> is used to dispatch the data to the
 *            relivant UMO.
 * @param endpoint
 *            the provider contains the endpointUri on which the receiver
 *            will listen on. The endpointUri can be anything and is
 *            specific to the receiver implementation i.e. an email address,
 *            a directory, a jms destination or port address.
 * @see UMOComponent
 * @see UMOEndpoint
 */
public AbstractMessageReceiver(UMOConnector connector, UMOComponent component, UMOEndpoint endpoint)
        throws InitialisationException {
    setConnector(connector);
    setComponent(component);
    setEndpoint(endpoint);
    listener = new DefaultInternalMessageListener();
    endpointUri = endpoint.getEndpointURI();
    if (connector instanceof AbstractConnector) {
        ThreadingProfile tp = ((AbstractConnector) connector).getReceiverThreadingProfile();
        if (serverSide) {
            tp.setThreadPriority(Thread.NORM_PRIORITY + 2);
        }
        workManager = tp.createWorkManager(connector.getName() + "." + endpoint.getName() + ".receiver");
        try {
            workManager.start();
        } catch (UMOException e) {
            throw new InitialisationException(e, this);
        }
    }

    connectionStrategy = this.connector.getConnectionStrategy();
    // if(connectionStrategy instanceof AbstractConnectionStrategy) {
    // ((AbstractConnectionStrategy)connectionStrategy).setDoThreading(
    // this.connector.getReceiverThreadingProfile().isDoThreading());
    // }
}

From source file:org.parosproxy.paros.core.proxy.ProxyServer.java

/**
 *
 * @return   true = the server is started successfully.
 *///from w  w  w .  j  a v a 2 s .c o  m
public synchronized int startServer(String ip, int port, boolean isDynamicPort) {

    if (isProxyRunning) {
        stopServer();
    }

    isProxyRunning = false;

    // ZAP: Set the name of the thread.
    thread = new Thread(this, "ZAP-ProxyServer");
    thread.setDaemon(true);
    // the priority below should be higher than normal to allow fast accept on the server socket
    thread.setPriority(Thread.NORM_PRIORITY + 1);

    proxySocket = null;
    for (int i = 0; i < 20 && proxySocket == null; i++) {
        try {
            proxySocket = createServerSocket(ip, port);
            proxySocket.setSoTimeout(PORT_TIME_OUT);
            isProxyRunning = true;

        } catch (UnknownHostException e) {
            // ZAP: Warn the user if the host is unknown
            if (View.isInitialised()) {
                View.getSingleton()
                        .showWarningDialog(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);

            } else {
                System.out.println(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);
            }

            return -1;
        } catch (BindException e) {
            if ("Cannot assign requested address".equals(e.getMessage())) {
                showErrorMessage(Constant.messages.getString("proxy.error.address") + " " + ip);
                return -1;
            } else if ("Permission denied".equals(e.getMessage())
                    || "Address already in use".equals(e.getMessage())) {
                if (!isDynamicPort) {
                    showErrorMessage(Constant.messages.getString("proxy.error.port") + " " + ip + ":" + port);
                    return -1;
                } else if (port < 65535) {
                    port++;
                }
            } else {
                handleUnknownException(e);
                return -1;
            }
        } catch (IOException e) {
            handleUnknownException(e);
            return -1;
        }

    }

    if (proxySocket == null) {
        return -1;
    }

    thread.start();

    return proxySocket.getLocalPort();

}