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:org.alfresco.mobile.android.application.managers.RenditionManagerImpl.java

public void display(RenditionRequest request) {
    // Prerequisites
    if (session == null) {
        setSession(SessionUtils.getSession(appContext));
    }//from w  ww  . j  av a 2s.  co m
    if (picasso == null) {
        picasso = new Builder(appContext).build();
    }

    // Cancel any previous request
    if (picasso != null) {
        picasso.cancelRequest(request.iv.get());
    }

    // Wrong identifier so display placeholder directly
    String url = null;
    if (TextUtils.isEmpty(request.itemId) || session == null) {
        request.iv.get().setImageResource(request.placeHolderId);
        return;
    }

    // Let's find how to display the itemId
    switch (request.typeId) {
    case TYPE_NODE:
        if (session instanceof RepositorySession) {
            url = getDocumentRendition(request.itemId, DocumentFolderService.RENDITION_THUMBNAIL);
            if (request.renditionTypeId == RenditionRequest.RENDITION_PREVIEW) {
                url = getDocumentRendition(request.itemId, DocumentFolderService.RENDITION_PREVIEW);
            }
            startPicasso(url, request);
            return;
        } else if (hasReference(request.itemId, request.renditionTypeId)) {
            url = getReference(request.itemId, request.renditionTypeId);
            startPicasso(url, request);
            return;
        }
        break;
    case TYPE_WORKFLOW:
        url = ((AbstractWorkflowService) session.getServiceRegistry().getWorkflowService())
                .getProcessDiagramUrl(request.itemId).toString();
        startPicasso(url, request);
        return;
    case TYPE_PERSON:
        if (session instanceof RepositorySession
                && session.getRepositoryInfo().getMajorVersion() >= OnPremiseConstant.ALFRESCO_VERSION_4) {
            url = OnPremiseUrlRegistry.getAvatarUrl(session, request.itemId);
            startPicasso(url, request);
            return;
        } else if (hasReference(request.itemId, request.renditionTypeId)) {
            url = getReference(request.itemId, request.renditionTypeId);
            startPicasso(url, request);
            return;
        }
        break;
    default:
        break;
    }

    // We don't know the url associated to the itemId, we need to find it
    // first.
    displayPlaceHolder(request.iv, request.placeHolderId);
    if (getReference(request.itemId, request.renditionTypeId) == null && activityRef != null) {
        addReference(request.itemId, AWAIT, request.renditionTypeId);
        urlRetrieverThread thread = new urlRetrieverThread(activityRef.get(), session, request);
        thread.setPriority(Thread.MIN_PRIORITY);
        if (request.renditionTypeId == RenditionRequest.RENDITION_PREVIEW) {
            thread.setPriority(Thread.NORM_PRIORITY);
        }
        final AsyncDrawable asyncDrawable = new AsyncDrawable(activityRef.get().getResources(), thread);
        request.iv.get().setImageDrawable(asyncDrawable);
        if (thread.getState() == Thread.State.NEW) {
            thread.start();
        }
    } else {
        request.iv.get().setImageResource(request.placeHolderId);
    }
}

From source file:org.apache.hadoop.fs.s3r.S3RFileSystem.java

/**
 * Get a named {@link ThreadFactory} that just builds daemon threads.
 * @param prefix name prefix for all threads created from the factory
 * @return a thread factory that creates named, daemon threads with
 *         the supplied exception handler and normal priority
 *//*  w w  w .ja v a2  s.c om*/
private static ThreadFactory newDaemonThreadFactory(final String prefix) {
    final ThreadFactory namedFactory = getNamedThreadFactory(prefix);
    return new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = namedFactory.newThread(r);
            if (!t.isDaemon()) {
                t.setDaemon(true);
            }
            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }
            return t;
        }

    };
}

From source file:net.spfbl.dnsbl.QueryDNSBL.java

/**
 * Configurao e intanciamento do servidor.
 * @throws java.net.SocketException se houver falha durante o bind.
 *///from w  w  w .  j  av  a2  s.c  o  m
public QueryDNSBL(int port) throws SocketException {
    super("SERVERDNS");
    setPriority(Thread.NORM_PRIORITY);
    // Criando conexes.
    Server.logDebug("binding DNSBL socket on port " + port + "...");
    PORT = port;
    SERVER_SOCKET = new DatagramSocket(port);
}

From source file:net.lightbody.bmp.proxy.jetty.util.ThreadPool.java

/**
 * Get the priority of the pool threads.
 * /*  www  . j ava2  s. co  m*/
 * @return the priority of the pool threads.
 */
public int getThreadsPriority() {
    int priority = Thread.NORM_PRIORITY;
    Object o = _pool.getAttribute(__PRIORITY);
    if (o != null) {
        priority = ((Integer) o).intValue();
    }
    return priority;
}

From source file:org.parosproxy.paros.extension.manualrequest.ManualRequestEditorDialog.java

protected void send(final Message aMessage) {
    final Thread t = new Thread(new Runnable() {
        @Override//from   ww w  .j  ava  2s  .co  m
        public void run() {
            try {
                getMessageSender().handleSendMessage(aMessage);
                postSend();
            } catch (SSLException sslEx) {
                StringBuilder strBuilder = new StringBuilder();

                strBuilder.append(Constant.messages.getString("network.ssl.error.connect"));
                strBuilder.append(((HttpMessage) aMessage).getRequestHeader().getURI().toString()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception"))
                        .append(sslEx.getMessage()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception.rootcause"))
                        .append(ExceptionUtils.getRootCauseMessage(sslEx)).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.help",
                        Constant.messages.getString("network.ssl.error.help.url")));
                logger.warn(strBuilder.toString());
                if (logger.isDebugEnabled()) {
                    logger.debug(sslEx, sslEx);
                }
                View.getSingleton().showWarningDialog(strBuilder.toString());
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
                View.getSingleton().showWarningDialog(e.getMessage());
            } finally {
                btnSend.setEnabled(true);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY);
    t.start();
}

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

public void start() {
    dataLoadWorkers = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() {
        final AtomicInteger threadNumber = new AtomicInteger(1);
        final String namePrefix = parameterService.getEngineName().toLowerCase() + "-data-load-worker-";

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(namePrefix + threadNumber.getAndIncrement());
            t.setDaemon(false);/*from  w  w  w .j  ava  2s .co m*/
            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }
            return t;
        }
    });
}

From source file:com.hqme.cm.cache.StreamingServer.java

public void run() {
    if (UntenCacheService.sIsDebugMode) {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
        Thread.currentThread().setName(getClass().getName());
    }//w  w  w. j  a v  a2  s .  c  o m

    isStopping = false;
    serverSocket = null;
    serverPortPrefs = new File(UntenCacheService.sPluginContext.getFilesDir(), tag_PlaybackPortNumber);
    try {
        String text = new BufferedReader(new InputStreamReader(new FileInputStream(serverPortPrefs), "UTF16"),
                1 << 10).readLine();
        serverPortNumber = Integer.valueOf(text.trim());
    } catch (Throwable ignore) {
        serverPortNumber = 0;
    }

    int retries = 2;
    while (retries-- > 0) {
        try {
            serverSocket = new ServerSocket(serverPortNumber);
            if (serverPortNumber == 0) {
                serverPortNumber = serverSocket.getLocalPort();
                try {
                    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(serverPortPrefs),
                            "UTF16");
                    writer.write(serverPortNumber + "\r\n");
                    writer.flush();
                    writer.close();
                } catch (Throwable ignore) {
                }
            }
            clientBox = new ClientBox[MAX_CLIENTS];
            retries = 0;

            UntenCacheService.debugLog(sTag, "run: Streaming Media Server is now active on TCP port # %d",
                    serverPortNumber);
            handleRequests();
        } catch (IOException fault) {
            fault.printStackTrace();
            try {
                serverPortPrefs.delete();
            } catch (Throwable ignore) {
            }
        }
    }
}

From source file:org.parosproxy.paros.model.Session.java

protected void open(final File file, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override//from w  w  w  . j av  a  2  s  .  co m
        public void run() {
            Exception thrownException = null;
            try {
                open(file.getAbsolutePath());
            } catch (Exception e) {
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionOpened(file, thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}

From source file:cn.ttyhuo.common.MyApplication.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  w w w  .  j a  v a  2  s  .c o  m*/
    //ImageLoaderConfiguration.createDefault(getBaseContext());
    //imageLoader.init(ImageLoaderConfiguration.createDefault(SpecialAlbumActivity.this));
    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.parosproxy.paros.model.Session.java

protected void open(final String sessionFile, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override//from  w w w  .  j a v  a2  s . c o m
        public void run() {
            Exception thrownException = null;
            try {
                open(sessionFile);
            } catch (Exception e) {
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionOpened(null, thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}