List of usage examples for java.lang Thread NORM_PRIORITY
int NORM_PRIORITY
To view the source code for java.lang Thread NORM_PRIORITY.
Click Source Link
From source file:org.openstreetmap.josm.data.imagery.TMSCachedTileLoader.java
/** * @param nameFormat see {@link Utils#newThreadFactory(String, int)} * @param workers number of worker thread to keep * @return new ThreadPoolExecutor that will use a @see HostLimitQueue based queue *//*from ww w. j av a 2 s. c o m*/ public static ThreadPoolExecutor getNewThreadPoolExecutor(String nameFormat, int workers) { HostLimitQueue workQueue = new HostLimitQueue(HOST_LIMIT.get().intValue()); ThreadPoolExecutor executor = new ThreadPoolExecutor(0, // 0 so for unused thread pools threads will eventually die, freeing also the threadpool workers, // do not this number of threads 300, // keepalive for thread TimeUnit.SECONDS, workQueue, Utils.newThreadFactory(nameFormat, Thread.NORM_PRIORITY)); workQueue.setExecutor(executor); return executor; }
From source file:org.apache.streams.threaded.controller.ThreadingController.java
public static ThreadingController getInstance() { synchronized (ThreadingController.class) { if (instance == null) { instance = new ThreadingController("Apache Streams [default]", NUM_PROCESSORS, NUM_PROCESSORS * 5, Thread.NORM_PRIORITY); }//from w w w . j av a 2 s. c o m return instance; } }
From source file:net.NettyEngine4.ServerServiceImpl.java
/** * run netty server//from ww w . j a va2s . c om * NioEventLoopGroup used for NIO Selector based Channels * two NioEventLoopGroup(AioEventLoopGroup) will be used. The first is * used to handle the accept of new connections and the second will serve the IO of them. * IoEventLoopGroupThread +1; * DefaultEventExecutorGroup ? * * bossExecutor:?SocketChannel * workerExecutorSocketChannel?channel/ * executionLogicHandlerThread???? * AIO ?channelgroup?group? * option() is for the NioServerSocketChannel that accepts incoming connections * childOption() is for the Channels accepted by the parent ServerChannel, * which is NioServerSocketChannel in this case. * * ServerBootstrap ?? parent channel * parent channel ? connections * ? connection ? child channel ?? */ @Override public void run() throws Exception { NioEventLoopGroup EventLoopGroupLister = new NioEventLoopGroup(0x1, new PriorityThreadFactory("@+main_reactor+@", Thread.NORM_PRIORITY)); NioEventLoopGroup IOEventLoopGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() + 1, new PriorityThreadFactory("@+sub_reactor+@", Thread.NORM_PRIORITY)); ServerBootstrap serverBootstrap = new ServerBootstrap(); try { serverBootstrap.group(EventLoopGroupLister, IOEventLoopGroup).channel(NioServerSocketChannel.class) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_REUSEADDR, true) //?? .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(false))// heap buf 's better .childOption(ChannelOption.SO_RCVBUF, 1048576).childOption(ChannelOption.SO_SNDBUF, 1048576) .childHandler(new ServerChannelInitializer());//used to serve the request for the {@link Channel}'s // Bind and start to accept incoming connections. ChannelFuture channelFuture = serverBootstrap .bind(new InetSocketAddress(Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort)).sync(); if (LOGGER.isDebugEnabled()) LOGGER.debug("server??:" + Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort); // Wait until the server socket is closed. // In this server, this does not happen, but you can do that to gracefully // shut down your server. channelFuture.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. EventLoopGroupLister.shutdownGracefully(); IOEventLoopGroup.shutdownGracefully(); } }
From source file:org.apache.streams.threaded.controller.ThreadingController.java
public static ThreadingController getInstanceHighPriority() { synchronized (ThreadingController.class) { if (instanceHighPriority == null) { instanceHighPriority = new ThreadingController("Apache Streams [high]", NUM_PROCESSORS, NUM_PROCESSORS * 7, Thread.NORM_PRIORITY + 2); }/*from w ww . ja v a2 s . com*/ return instanceHighPriority; } }
From source file:org.rhq.core.pc.util.LoggingThreadFactory.java
/** * @see java.util.concurrent.ThreadFactory#newThread(Runnable) *//*w w w . j a va 2 s . co m*/ public Thread newThread(Runnable r) { Thread t = new Thread(group, r, poolName + "-" + threadNumber.getAndIncrement()); t.setDaemon(this.daemon); if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } t.setUncaughtExceptionHandler(this); return t; }
From source file:rems.Program.java
/** * @param args the command line arguments *//*w w w . ja va 2s. c o m*/ public static void main(String[] args) { try { Global.UsrsOrg_ID = 3; Global.dataBasDir = "C:\\1_DESIGNS\\MYAPPS\\Enterprise_Management_System\\Enterprise_Management_System\\bin\\Debug\\Images\\test_database"; Global.rnnrsBasDir = "C:\\1_DESIGNS\\MYAPPS\\Enterprise_Management_System\\Enterprise_Management_System\\bin\\Debug\\bin"; String pname = ManagementFactory.getRuntimeMXBean().getName(); if (pname.contains("@")) { Global.pid = Integer.parseInt(pname.substring(0, pname.lastIndexOf("@"))); } else { Global.pid = Thread.currentThread().getId(); } Global.HostOSNme = System.getProperty("os.name"); System.out.println(Global.pid); System.out.println(Global.HostOSNme); String[] macDet = Global.getMachDetails(); System.out.println(Arrays.toString(macDet)); System.out.println(args.length); System.out.println(Arrays.toString(args)); Global.errorLog += Global.pid + System.getProperty("line.separator") + Global.HostOSNme + System.getProperty("line.separator") + Arrays.toString(Global.getMachDetails()) + System.getProperty("line.separator"); //Global.writeToLog(); if (args.length >= 8) { Global.rnnrsBasDir = StringUtils.strip(args[7], "\""); runnerName = StringUtils.strip(args[5], "\""); Global.errorLog = args[0] + System.getProperty("line.separator") + args[1] + System.getProperty("line.separator") + args[2] + System.getProperty("line.separator") + "********************" + System.getProperty("line.separator") + args[4] + System.getProperty("line.separator") + args[5] + System.getProperty("line.separator") + args[6] + System.getProperty("line.separator") + Global.rnnrsBasDir + System.getProperty("line.separator"); if (args.length >= 10) { Global.callngAppType = StringUtils.strip(args[8], "\""); Global.dataBasDir = StringUtils.strip(args[9], "\""); Global.errorLog += args[8] + System.getProperty("line.separator") + args[9] + System.getProperty("line.separator"); if (args.length == 11) { Global.AppUrl = StringUtils.strip(args[10], "\""); Global.errorLog += args[10] + System.getProperty("line.separator"); } } Global.errorLog += "PID: " + Global.pid + " Running on: " + macDet[0] + " / " + macDet[1] + " / " + macDet[2]; Global.writeToLog(); Global.runID = Long.valueOf(args[6]); do_connection(args[0], args[1], args[2], args[3], args[4]); Global.appStatPath = Global.rnnrsBasDir; //Program.updateRates("2015-07-02"); if (Global.runID > 0) { Global.rnUser_ID = Long.valueOf( Global.getGnrlRecNm("rpt.rpt_report_runs", "rpt_run_id", "run_by", Global.runID)); Global.UsrsOrg_ID = Global.getUsrOrgID(Global.rnUser_ID); } if (!Global.globalSQLConn.isClosed()) { Global.globalSQLConn.close(); boolean isLstnrRnng = false; if (Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) { int isIPAllwd = Global.getEnbldPssblValID(macDet[2], Global.getEnbldLovID("Allowed IP Address for Request Listener")); int isDBAllwd = Global.getEnbldPssblValID(Global.Dbase, Global.getEnbldLovID("Allowed DB Name for Request Listener")); if (isIPAllwd <= 0 || isDBAllwd <= 0) { Program.killThreads(); Thread.currentThread().interrupt(); //Program.killThreads(); return; } isLstnrRnng = Global.isRunnrRnng(Program.runnerName); if (isLstnrRnng == true) { Program.killThreads(); Thread.currentThread().interrupt(); //Program.killThreads(); return; } } Global.errorLog = "Successfully Connected to Database\r\n" + String.valueOf(isLstnrRnng) + System.getProperty("line.separator"); Global.writeToLog(); String rnnPryty = Global.getGnrlRecNm("rpt.rpt_prcss_rnnrs", "rnnr_name", "crnt_rnng_priority", Program.runnerName); if (isLstnrRnng == false && Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) { Global.updatePrcsRnnrCmd(Program.runnerName, "0", -1); thread1 = new RqstLstnrUpdtrfunc("ThreadOne"); thread1.setDaemon(true); thread1.setName("ThreadOne"); thread1.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadOne thread..."); thread1.start(); Global.minimizeMemory(); if (Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) { //Thread for Generating Run Requests for Scheduled Programs/Reports thread2 = new GnrtSchldRnsfunc("ThreadTwo"); thread2.setDaemon(true); thread2.setName("ThreadTwo"); thread2.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadTwo thread..."); thread2.start(); //Thread for Generating Run Requests for Scheduled Alerts thread6 = new GnrtSchldAlertsfunc("ThreadSix"); thread6.setDaemon(true); thread6.setName("ThreadSix"); thread6.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadSix thread..."); thread6.start(); //Thread for Monitoring Scheduled Request Runs that are due but not running // and starting their appropriate process runners thread3 = new MntrSchdldRqtsNtRnngfunc("ThreadThree"); thread3.setDaemon(true); thread3.setName("ThreadThree"); thread3.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadThree thread..."); thread3.start(); //Thread for Monitoring User Request Runs that are due but not running // and starting their appropriate process runners thread4.setDaemon(true); thread4.setName("ThreadFour"); thread4.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadFour thread..."); thread4.start(); //Thread for Generating Run Requests for Scheduled Alerts thread7 = new MntrSchdldAlertsNtRnngfunc("ThreadSeven"); thread7.setDaemon(true); thread7.setName("ThreadSeven"); thread7.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadSeven thread..."); thread7.start(); //Thread for Running Requests for User Initiated Alerts thread8 = new MntrUserAlertsNtRnngfunc("ThreadEight"); thread8.setDaemon(true); thread8.setName("ThreadEight"); thread8.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadEight thread..."); thread8.start(); } } else { //Thread for running the actual Code behind the Request Run if this is the //Program supposed to run that request //i.e. if Global.runID >0 Global.minimizeMemory(); if (Global.runID > 0) { thread1 = new RqstLstnrUpdtrfunc("ThreadOne"); thread1.setDaemon(true); thread1.setName("ThreadOne"); thread1.setPriority(Thread.MIN_PRIORITY); //System.out.println("Starting ThreadOne thread..."); thread1.start(); thread5 = new RunActualRqtsfunc("ThreadFive"); thread5.setDaemon(true); thread5.setName("ThreadFive"); //System.out.println("Starting ThreadFive thread..."); if (rnnPryty.equals("1-Highest")) { thread1.setPriority(Thread.MAX_PRIORITY); } else if (rnnPryty.equals("2-AboveNormal")) { thread1.setPriority(7); } else if (rnnPryty.equals("3-Normal")) { thread1.setPriority(Thread.NORM_PRIORITY); } else if (rnnPryty.equals("4-BelowNormal")) { thread1.setPriority(3); } else { thread1.setPriority(1); } thread5.start(); } // Allow counting for 10 seconds. //Thread.Sleep(1000); } } } } catch (NumberFormatException ex) { Global.errorLog = ex.getMessage() + System.getProperty("line.separator") + Arrays.toString(ex.getStackTrace()); String fileLoc = Global.rnnrsBasDir + "/log_files/"; Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("ddMMMyyyyHHmmss"); fileLoc += "Global.errorLog" + ft.format(dNow.getTime()) + ".rho"; PrintWriter fileWriter; try { fileWriter = new PrintWriter(fileLoc, "UTF-8"); fileWriter.println(Global.errorLog); fileWriter.close(); } catch (FileNotFoundException ex1) { Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1); } catch (UnsupportedEncodingException ex1) { Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1); } killThreads(); } catch (SQLException ex) { Global.errorLog = ex.getMessage() + System.getProperty("line.separator") + Arrays.toString(ex.getStackTrace()); String fileLoc = Global.rnnrsBasDir + "/log_files/"; Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("ddMMMyyyyHHmmss"); fileLoc += "Global.errorLog" + ft.format(dNow.getTime()) + ".rho"; PrintWriter fileWriter; try { fileWriter = new PrintWriter(fileLoc, "UTF-8"); fileWriter.println(Global.errorLog); fileWriter.close(); } catch (FileNotFoundException ex1) { Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1); } catch (UnsupportedEncodingException ex1) { Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1); } killThreads(); } finally { } }
From source file:net.pms.util.BasicThreadFactory.java
/** * Creates a new {@link BasicThreadFactory} using the default * {@link ThreadGroup} and priority {@link Thread#NORM_PRIORITY}. * <p>//from w w w.j av a 2s . c o m * The {@link Thread} names generated by the new {@link BasicThreadFactory} * is created by calling {@link String#format} with {@code namePattern} as * the "format" and pool- and thread number as arguments. The formatting * rules are those of {@link java.util.Formatter}. * <p> * No more than two variables of type {@code %d} or {@code %s} is allowed in * {@code namePattern}, and they will be substituted as follows: * <ul> * <li>No variables: All {@link Thread} names generated by this * {@link ThreadFactory} will be equal to {@code namePattern}.</li> * <li>One variable: Only thread number will be used, pool number isn't * used.</li> * <li>Two variables: Pool number will be used for the first variable in * {@code namePattern}, thread number for the second. * </ul> * * @param namePattern The {@link java.util.Formatter} formatted * {@link String} from which to generate {@link Thread} names. */ public BasicThreadFactory(String namePattern) { this(namePattern, Thread.NORM_PRIORITY, null); }
From source file:com.abiansoftware.lib.reader.AbianReaderApplication.java
@Override public void onCreate() { s_singleton = this; ImageLoader theImageLoader = ImageLoader.getInstance(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 1).memoryCacheSize(2 * 1024 * 1024) .denyCacheImageMultipleSizesInMemory() //.enableLogging() .build();//from ww w .j a v a 2 s . com theImageLoader.init(config); s_asyncHttpClient = new AsyncHttpClient(); s_asyncHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); m_data = new AbianReaderData(); m_dataFetcher = new AbianReaderDataFetcher(); WindowManager theWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display theDefaultDisplay = theWindowManager.getDefaultDisplay(); DisplayMetrics theDisplayMetrics = new DisplayMetrics(); theDefaultDisplay.getMetrics(theDisplayMetrics); s_width = theDisplayMetrics.widthPixels; s_height = theDisplayMetrics.heightPixels; m_handlerVector = new Vector<Handler>(); m_adapterVector = new Vector<BaseAdapter>(); m_bSplashScreenHasBeenShown = false; m_readUrlArrayList = null; loadReadUrlList(); super.onCreate(); }
From source file:org.apache.lens.server.api.events.AsyncEventListener.java
/** * Create an asynchronous event listener which uses a thread poool to process events. * * @param poolSize size of the event processing pool * @param timeOutSeconds time out in seconds when an idle thread is destroyed * @param isDaemon if the threads used to process should be daemon threads, * if false, then implementation should call stop() * to stop the thread pool */// w ww . ja va 2 s . c o m public AsyncEventListener(int poolSize, long timeOutSeconds, final boolean isDaemon) { eventQueue = new LinkedBlockingQueue<>(); ThreadFactory factory = new BasicThreadFactory.Builder().namingPattern(getName() + "_AsyncThread-%d") .daemon(isDaemon).priority(Thread.NORM_PRIORITY).build(); // fixed pool with min and max equal to poolSize processor = new ThreadPoolExecutor(poolSize, poolSize, timeOutSeconds, TimeUnit.SECONDS, eventQueue, factory); processor.allowCoreThreadTimeOut(true); }
From source file:org.quartz.core.QuartzSchedulerThread.java
/** * <p>// www .j ava2s .co m * Construct a new <code>QuartzSchedulerThread</code> for the given * <code>QuartzScheduler</code> as a non-daemon <code>Thread</code> * with normal priority. * </p> */ QuartzSchedulerThread(QuartzScheduler qs, QuartzSchedulerResources qsRsrcs, SchedulingContext ctxt) { this(qs, qsRsrcs, ctxt, qsRsrcs.getMakeSchedulerThreadDaemon(), Thread.NORM_PRIORITY); }