Example usage for java.lang Thread MAX_PRIORITY

List of usage examples for java.lang Thread MAX_PRIORITY

Introduction

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

Prototype

int MAX_PRIORITY

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

Click Source Link

Document

The maximum priority that a thread can have.

Usage

From source file:org.puder.trs80.EmulatorActivity.java

private void startCPUThread() {
    cpuThread = new Thread(new Runnable() {

        @Override//from w w  w  .  j av  a  2s  . com
        public void run() {
            XTRS.run();
        }
    });
    XTRS.setRunning(true);
    cpuThread.setPriority(Thread.MAX_PRIORITY);
    cpuThread.start();
}

From source file:org.rzo.yajsw.app.WrapperManagerImpl.java

public void start() {

    connector = new ClientBootstrap(new OioClientSocketChannelFactory(
            //executor,
            executor));/*from w ww .  jav a 2 s  .co m*/
    // add logging
    if (_debug) {
        connector.getPipeline().addLast("logger", new LoggingFilter(log, "app"));
        log.info("Logging ON");
    }

    // add a framer to split incoming bytes to message chunks 
    connector.getPipeline().addLast("framer",
            new DelimiterBasedFrameDecoder(8192, true, Delimiters.nulDelimiter()));

    // add message coding
    connector.getPipeline().addLast("messageEncoder", new MessageEncoder());
    connector.getPipeline().addLast("messageDecoder", new MessageDecoder());

    // pinger is a cycler with high priority threads
    // sends ping messages within a ping interval
    _pinger = new Cycler(getPingInterval(), 0,
            Executors.newCachedThreadPool(new DaemonThreadFactory("pinger", Thread.MAX_PRIORITY)),
            new Runnable() {
                long start = System.currentTimeMillis();

                public void run() {
                    if (_session != null && _session.isConnected() && !_stopping && !_appearHanging) {
                        _session.write(new Message(Constants.WRAPPER_MSG_PING, null));
                        start = System.currentTimeMillis();
                    } else if (_haltAppOnWrapper && (System.currentTimeMillis() - start) > _startupTimeout) {
                        System.out.println("no connection to wrapper during " + (_startupTimeout / 1000)
                                + "seconds -> System.exit(-1)");
                        System.out.println(
                                "if this is this is due to server overload consider increasing wrapper.startup.timeout");
                        System.exit(-1);
                    }
                }
            });
    _pinger.start();

    // connect
    connector.setOption("remoteAddress", new InetSocketAddress("127.0.0.1", _port));
    connector.setOption("connectTimeoutMillis", 10 * 1000);
    connector.setOption("reuseAddress", true);
    connector.setOption("tcpNoDelay", true);
    connector.getPipeline().addLast("handler", new WrapperHandler());

    // handler should process messages in a separate thread

    reconnect();
    /*
     * try { if (_config.getInt("wrapper.action.port") > 0) { _actionHandler
     * = new ActionHandler(this, _config); _actionHandler.start(); } } catch
     * (Exception ex) { log.info("could not start action handler " +
     * ex.getMessage()); }
     */

}

From source file:org.rhq.bundle.ant.AntMain.java

/** Handle the -nice argument. */
private int handleArgNice(String[] args, int pos) {
    try {//from   w ww .j ava2  s . c om
        threadPriority = Integer.decode(args[++pos]);
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        throw new BuildException("You must supply a niceness value (1-10)" + " after the -nice option");
    } catch (NumberFormatException e) {
        throw new BuildException("Unrecognized niceness value: " + args[pos]);
    }

    if (threadPriority.intValue() < Thread.MIN_PRIORITY || threadPriority.intValue() > Thread.MAX_PRIORITY) {
        throw new BuildException("Niceness value is out of the range 1-10");
    }
    return pos;
}

From source file:com.googlecode.fascinator.indexer.SolrWrapperQueueConsumer.java

/**
 * Sets the priority level for the thread. Used by the OS.
 * // w  w  w.jav a 2  s.  c  o m
 * @param newPriority The priority level to set the thread at
 */
@Override
public void setPriority(int newPriority) {
    if (newPriority >= Thread.MIN_PRIORITY && newPriority <= Thread.MAX_PRIORITY) {
        thread.setPriority(newPriority);
    }
}

From source file:org.texai.torrent.PeerCoordinator.java

/** Quits the tracker client and peers. */
public void quit() {
    isQuit = true;//w ww  .jav  a 2 s  .c om
    LOGGER.info("halting tracker client");
    trackerClient.quit();
    LOGGER.info("disconnecting the peers  ********");
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    synchronized (peerDictionary) {
        LOGGER.info("obtained lock on the peers");

        // Stop peer checker task.
        peerCheckerTimer.cancel();

        // Stop peers.
        final Iterator<Peer> peers_iter = peerDictionary.values().iterator();
        while (peers_iter.hasNext()) {
            final Peer peer = peers_iter.next();
            LOGGER.info("disconnecting " + peer);
            peer.disconnect();
            peers_iter.remove();
        }
        LOGGER.info("peers disconnected  ********");
    }
}

From source file:net.dv8tion.jda.core.requests.WebSocketClient.java

protected void setupKeepAlive(long timeout) {
    keepAliveThread = new Thread(() -> {
        while (connected) {
            try {
                sendKeepAlive();/*from  www  . j a  v a2 s. c om*/

                //Sleep for heartbeat interval
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                //connection got cut... terminating keepAliveThread
                break;
            }
        }
    });
    keepAliveThread.setName(api.getIdentifierString() + " MainWS-KeepAlive Thread");
    keepAliveThread.setPriority(Thread.MAX_PRIORITY);
    keepAliveThread.setDaemon(true);
    keepAliveThread.start();
}

From source file:org.apache.hadoop.mapred.buffer.Manager.java

public void open() throws IOException {
    Configuration conf = tracker.conf();
    int maxMaps = conf.getInt("mapred.tasktracker.map.tasks.maximum", 2);
    int maxReduces = conf.getInt("mapred.tasktracker.reduce.tasks.maximum", 1);

    InetSocketAddress serverAddress = getServerAddress(conf);
    this.server = RPC.getServer(this, serverAddress.getHostName(), serverAddress.getPort(),
            maxMaps + maxReduces, false, conf);
    this.server.start();

    this.requestTransfer.setPriority(Thread.MAX_PRIORITY);
    this.requestTransfer.start();

    /** The server socket and selector registration */
    InetSocketAddress controlAddress = getControlAddress(conf);
    this.controlPort = controlAddress.getPort();
    this.channel = ServerSocketChannel.open();
    this.channel.socket().bind(controlAddress);

    this.acceptor = new Thread() {
        @Override//from w ww .  j  a v  a 2 s  . c o  m
        public void run() {
            while (!isInterrupted()) {
                SocketChannel connection = null;
                try {
                    connection = channel.accept();
                    DataInputStream in = new DataInputStream(connection.socket().getInputStream());
                    int numRequests = in.readInt();
                    for (int i = 0; i < numRequests; i++) {
                        BufferRequest request = BufferRequest.read(in);
                        if (request instanceof ReduceBufferRequest) {
                            add((ReduceBufferRequest) request);
                            LOG.info("add new request " + request);
                        } else if (request instanceof MapBufferRequest) {
                            add((MapBufferRequest) request);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (connection != null)
                            connection.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    };
    this.acceptor.setDaemon(true);
    this.acceptor.setPriority(Thread.MAX_PRIORITY);
    this.acceptor.start();

    this.serviceQueue = new Thread() {
        public void run() {
            List<OutputFile> service = new ArrayList<OutputFile>();
            while (!isInterrupted()) {
                try {
                    OutputFile o = queue.take();
                    service.add(o);
                    queue.drainTo(service);
                    for (OutputFile file : service) {
                        try {
                            if (file != null)
                                add(file);
                        } catch (Throwable t) {
                            t.printStackTrace();
                            LOG.error("Error service file: " + file + ". " + t);
                        }
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                    LOG.error(t);
                } finally {
                    service.clear();
                }
            }
            LOG.info("Service queue thread exit.");
        }
    };
    this.serviceQueue.setPriority(Thread.MAX_PRIORITY);
    this.serviceQueue.setDaemon(true);
    this.serviceQueue.start();
}

From source file:com.nuvolect.deepdive.probe.DecompileApk.java

private JSONObject unpackApk() {

    final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override// w  w w  .  j av a2s . c o  m
        public void uncaughtException(Thread t, Throwable e) {

            LogUtil.log(LogUtil.LogType.DECOMPILE, "Uncaught exception: " + e.toString());
            m_progressStream.putStream("Uncaught exception: " + t.getName());
            m_progressStream.putStream("Uncaught exception: " + e.toString());
        }
    };

    m_unpack_apk_time = System.currentTimeMillis(); // Save start time for tracking

    m_unpackApkThread = new Thread(m_threadGroup, new Runnable() {
        @Override
        public void run() {
            boolean success = false;
            try {

                m_progressStream = new ProgressStream(
                        new OmniFile(m_volumeId, m_appFolderPath + "unpack_apk_log.txt"));
                m_progressStream.putStream("Unpack APK starting");
                if (m_apkFile.exists() && m_apkFile.isFile()) {

                    // Extract all files except for XML, to be extracted later
                    success = ApkZipUtil.unzipAllExceptXML(m_apkFile, m_appFolder, m_progressStream);

                    ApkParser apkParser = ApkParser.create(m_apkFile.getStdFile());
                    ArrayList<OmniFile> dexFiles = new ArrayList<>();

                    // Get a list of all files in the APK and iterate and extract by type
                    List<String> paths = OmniZip.getFilesList(m_apkFile);
                    for (String path : paths) {

                        OmniFile file = new OmniFile(m_volumeId, m_appFolderPath + path);
                        OmniUtil.forceMkdirParent(file);

                        String extension = FilenameUtils.getExtension(path);

                        if (extension.contentEquals("xml")) {

                            String xml = apkParser.transBinaryXml(path);
                            OmniUtil.writeFile(file, xml);
                            m_progressStream.putStream("Translated: " + path);
                        }
                        if (extension.contentEquals("dex")) {
                            dexFiles.add(file);
                        }
                    }
                    paths = null; // Release memory

                    // Write over manifest with unencoded version
                    String manifestXml = apkParser.getManifestXml();
                    OmniFile manifestFile = new OmniFile(m_volumeId, m_appFolderPath + "AndroidManifest.xml");
                    OmniUtil.writeFile(manifestFile, manifestXml);
                    m_progressStream.putStream("Translated and parsed: " + "AndroidManifest.xml");

                    // Uses original author CaoQianLi's apk-parser
                    // compile 'net.dongliu:apk-parser:2.1.7'
                    //                        for( CertificateMeta cm : apkParser.getCertificateMetaList()){
                    //
                    //                            m_progressStream.putStream("Certficate base64 MD5: "+cm.getCertBase64Md5());
                    //                            m_progressStream.putStream("Certficate MD5: "+cm.getCertMd5());
                    //                            m_progressStream.putStream("Sign algorithm OID: "+cm.getSignAlgorithmOID());
                    //                            m_progressStream.putStream("Sign algorithm: "+cm.getSignAlgorithm());
                    //                        }

                    for (OmniFile f : dexFiles) {

                        String formatted_count = String.format(Locale.US, "%,d", f.length()) + " bytes";
                        m_progressStream.putStream("DEX extracted: " + f.getName() + ": " + formatted_count);
                    }
                    dexFiles = new ArrayList<>();// Release memory

                    CertificateMeta cm = null;
                    try {
                        cm = apkParser.getCertificateMeta();
                        m_progressStream.putStream("Certficate base64 MD5: " + cm.certBase64Md5);
                        m_progressStream.putStream("Certficate MD5: " + cm.certMd5);
                        m_progressStream.putStream("Sign algorithm OID: " + cm.signAlgorithmOID);
                        m_progressStream.putStream("Sign algorithm: " + cm.signAlgorithm);

                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }

                    m_progressStream.putStream("ApkSignStatus: " + apkParser.verifyApk());

                    /**
                     * Create a file for the user to include classes to omit in the optimize DEX task.
                     */
                    OmniFile optimizedDexOF = new OmniFile(m_volumeId,
                            m_appFolderPath + OPTIMIZED_CLASSES_EXCLUSION_FILENAME);
                    if (!optimizedDexOF.exists()) {

                        String assetFilePath = CConst.ASSET_DATA_FOLDER + OPTIMIZED_CLASSES_EXCLUSION_FILENAME;
                        OmniFile omniFile = new OmniFile(m_volumeId,
                                m_appFolderPath + OPTIMIZED_CLASSES_EXCLUSION_FILENAME);
                        OmniUtil.copyAsset(m_ctx, assetFilePath, omniFile);

                        m_progressStream.putStream("File created: " + OPTIMIZED_CLASSES_EXCLUSION_FILENAME);
                    }
                    /**
                     * Create a README file for the user.
                     */
                    OmniFile README_file = new OmniFile(m_volumeId, m_appFolderPath + README_FILENAME);
                    if (!README_file.exists()) {

                        String assetFilePath = CConst.ASSET_DATA_FOLDER + README_FILENAME;
                        OmniFile omniFile = new OmniFile(m_volumeId, m_appFolderPath + README_FILENAME);
                        OmniUtil.copyAsset(m_ctx, assetFilePath, omniFile);

                        m_progressStream.putStream("File created: " + README_FILENAME);
                    }
                } else {
                    m_progressStream.putStream("APK not found. Select Extract APK.");
                }

            } catch (Exception | StackOverflowError e) {
                m_progressStream.putStream(e.toString());
            }
            String time = TimeUtil.deltaTimeHrMinSec(m_unpack_apk_time);
            m_unpack_apk_time = 0;
            if (success) {
                m_progressStream.putStream("Unpack APK complete: " + time);
            } else {
                m_progressStream.putStream("Unpack APK failed: " + time);
            }
            m_progressStream.close();

        }
    }, UNZIP_APK_THREAD, STACK_SIZE);

    m_unpackApkThread.setPriority(Thread.MAX_PRIORITY);
    m_unpackApkThread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
    m_unpackApkThread.start();

    final JSONObject wrapper = new JSONObject();
    try {
        wrapper.put("unpack_apk_thread", getThreadStatus(true, m_unpackApkThread));

    } catch (JSONException e) {
        LogUtil.logException(LogUtil.LogType.DECOMPILE, e);
    }

    return wrapper;
}

From source file:au.com.redboxresearchdata.fascinator.plugins.JsonHarvestQueueConsumer.java

public void setPriority(int newPriority) {
    if (newPriority >= Thread.MIN_PRIORITY && newPriority <= Thread.MAX_PRIORITY) {
        thread.setPriority(newPriority);
    }/*from ww w  .  j  a va 2  s  .  c o m*/
}

From source file:ffx.potential.nonbonded.ReciprocalSpace.java

private double initConvolution() {

    /**//from w  w  w.  j a v a 2 s  .c o  m
     * Store the current reciprocal space grid dimensions.
     */
    int fftXCurrent = fftX;
    int fftYCurrent = fftY;
    int fftZCurrent = fftZ;

    double density = forceField.getDouble(ForceFieldDouble.PME_MESH_DENSITY, 1.2);

    int nX = forceField.getInteger(ForceFieldInteger.PME_GRID_X, -1);
    if (nX < 2) {
        nX = (int) Math.floor(crystal.a * density) + 1;
        if (nX % 2 != 0) {
            nX += 1;
        }
        while (!Complex.preferredDimension(nX)) {
            nX += 2;
        }
    }
    int nY = forceField.getInteger(ForceFieldInteger.PME_GRID_Y, -1);
    if (nY < 2) {
        nY = (int) Math.floor(crystal.b * density) + 1;
        if (nY % 2 != 0) {
            nY += 1;
        }
        while (!Complex.preferredDimension(nY)) {
            nY += 2;
        }
    }
    int nZ = forceField.getInteger(ForceFieldInteger.PME_GRID_Z, -1);
    if (nZ < 2) {
        nZ = (int) Math.floor(crystal.c * density) + 1;
        if (nZ % 2 != 0) {
            nZ += 1;
        }
        while (!Complex.preferredDimension(nZ)) {
            nZ += 2;
        }
    }

    fftX = nX;
    fftY = nY;
    fftZ = nZ;

    /**
     * Populate the matrix that fractionalizes multipoles.
     */
    transformMultipoleMatrix();
    /**
     * Populate the matrix that convert fractional potential components into
     * orthogonal Cartesian coordinates.
     */
    transformFieldMatrix();
    /**
     * Compute the Cartesian to fractional matrix.
     */
    for (int i = 0; i < 3; i++) {
        a[0][i] = fftX * crystal.A[i][0];
        a[1][i] = fftY * crystal.A[i][1];
        a[2][i] = fftZ * crystal.A[i][2];
    }

    fftSpace = fftX * fftY * fftZ * 2;
    boolean dimChanged = fftX != fftXCurrent || fftY != fftYCurrent || fftZ != fftZCurrent;

    switch (fftMethod) {
    case PJ:
        if (pjFFT3D == null || dimChanged) {
            pjFFT3D = new Complex3DParallel(fftX, fftY, fftZ, fftTeam, recipSchedule);
            if (splineGrid == null || splineGrid.length < fftSpace) {
                splineGrid = new double[fftSpace];
            }
            splineBuffer = DoubleBuffer.wrap(splineGrid);
        }
        pjFFT3D.setRecip(generalizedInfluenceFunction());
        cudaFFT3D = null;
        clFFT3D = null;
        gpuThread = null;
        break;
    case CUDA:
        if (cudaFFT3D == null || dimChanged) {
            if (cudaFFT3D != null) {
                cudaFFT3D.free();
            }
            cudaFFT3D = new Complex3DCuda(fftX, fftY, fftZ);
            gpuThread = new Thread(cudaFFT3D);
            gpuThread.setPriority(Thread.MAX_PRIORITY);
            gpuThread.start();
            splineBuffer = cudaFFT3D.getDoubleBuffer();
        }
        cudaFFT3D.setRecip(generalizedInfluenceFunction());
        pjFFT3D = null;
        clFFT3D = null;
        break;
    case OPENCL:
        if (clFFT3D == null || dimChanged) {
            if (clFFT3D != null) {
                clFFT3D.free();
            }
            clFFT3D = new Complex3DOpenCL(fftX, fftY, fftZ);
            gpuThread = new Thread(clFFT3D);
            gpuThread.setPriority(Thread.MAX_PRIORITY);
            gpuThread.start();
            splineBuffer = clFFT3D.getDoubleBuffer();
        }
        clFFT3D.setRecip(generalizedInfluenceFunction());
        pjFFT3D = null;
        cudaFFT3D = null;
        break;
    }

    switch (gridMethod) {
    case SPATIAL:
        if (spatialDensityRegion == null || dimChanged) {
            spatialDensityRegion = new SpatialDensityRegion(fftX, fftY, fftZ, splineGrid, bSplineOrder, nSymm,
                    10, threadCount, crystal, atoms, coordinates);
            if (fftMethod != FFTMethod.PJ) {
                spatialDensityRegion.setGridBuffer(splineBuffer);
            }
        } else {
            spatialDensityRegion.setCrystal(crystal, fftX, fftY, fftZ);
            spatialDensityRegion.coordinates = coordinates;
        }
        break;
    case ROW:
        if (rowRegion == null || dimChanged) {
            rowRegion = new RowRegion(fftX, fftY, fftZ, splineGrid, bSplineOrder, nSymm, threadCount, crystal,
                    atoms, coordinates);
            if (fftMethod != FFTMethod.PJ) {
                rowRegion.setGridBuffer(splineBuffer);
            }
        } else {
            rowRegion.setCrystal(crystal, fftX, fftY, fftZ);
            rowRegion.coordinates = coordinates;
        }

        break;
    case SLICE:
    default:
        if (sliceRegion == null || dimChanged) {
            sliceRegion = new SliceRegion(fftX, fftY, fftZ, splineGrid, bSplineOrder, nSymm, threadCount,
                    crystal, atoms, coordinates);
            if (fftMethod != FFTMethod.PJ) {
                sliceRegion.setGridBuffer(splineBuffer);
            }
        } else {
            sliceRegion.setCrystal(crystal, fftX, fftY, fftZ);
            sliceRegion.coordinates = coordinates;
        }
    }
    return density;
}