ThreadPoolExecutor and using priority to determine what threads will run

Hello,
I am fairly new to Java, so I apologize if there is an obvious answer.
The ThreadPoolExecutor is a great class for thread management. What I would like to do is have a priority scheme that would determine what thread should be run next. For example, let's say I have 100 threads and a limit of 20 threads. Each thread that is executed should have a mechanism to indicate a priority. When a thread becomes available in the pool, the priority value should be checked to determine which thread to run. This would allow me to get important tasks completed quickly. Right now it appears that there is a FIFO order to threads. I tried wrapping the runnable object in a Thread, but that didn't seem to have an effect.
I am using a Fixed thread Pool:
      loThreadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(MAXTHREADS); (MAXTHREADS=20)I have tried creating a PriorityBlockingQueue with a comparator that compares the thread priority, but nothing seems to work.
  public Constructor() {
loThreadPoolExecutor = new ThreadPoolExecutor(MAXTHREADS,MAXTHREADS*2,0,TimeUnit.SECONDS,new PriorityBlockingQueue(11,new PrvComparator()));
    private class PrvComparator implements Comparator  {
          public int compare(Object o1, Object o2) {
               // TODO Auto-generated method stub
               Thread t1 = (Thread) o1;
               Thread t2 = (Thread) o2;
               System.out.println("P1="+t1.getPriority()+ " P2="+t2.getPriority());
               if (t1.getPriority()<t2.getPriority()) return -1;
               if (t1.getPriority()>t2.getPriority()) return 1;
               else return 0;
               //PriorityBlockingQueue
          }I would appreciate any help.

What are you trying to prioritize? The order on which tasks come off the work queue, or the order in which they get completed?
Doing the first is simple but restricted. Your tasks are Comparable and define their own priority and you use a PriorityBlockingQueue. But you are restricted to using the execute() method with Runnable's that are Comparable. submit() will wrap the task in a FutureTask that isn't Comparable and so will cause a ClassCastException.
Doing the second is difficult. Even if your threads have different priorities then don't queue for tasks in priority order, so the thread priority when taking a task is irrelevant. You could change the thread priority based on the priority of the task once it starts executing. But Thread priorities are only a hint to the scheduler that you think Thread A is more important than Thread B. On some platforms priorities will have little observable effects - whereas on other it can be drastic if you use priorities that are too high or too low. The mapping from Java priority to OS thread priority is platform specific. See for example http://java.sun.com/javase/6/docs/technotes/guides/vm/thread-priorities.html

Similar Messages

  • Is there any quick and dirty way to determine what something will look like

    Hi,
    Is there any way (rule of thumb) to determine what something will look like when printed.
    for example.
    I am doing a composite (hope this is the right word). It will have some people sitting at a table and I want to have another layer with another picture behind it.
    I plan for the output to be fairly small (print size), say 4 x 5 or whatever.
    Now, if I go to the internet and google (or mamma.com) and search for images (large) and it comes back to me, I will see pictures that are (for example) 800 x 526 pixels 367 kb, or 940 x 480 pixels 166 kb.
    I would have to assume the 367 kb will print at better resolution, but if i liked the 166 kb picture better, is there a quick and dirty way to determine if it would print better (say 250 or 300 dpi or whatever) or not?
    So, bottome line,
    Assume my output picture will be 4 x 5 (and I want 300dpi (or is it ppi)
    How do quickly look at google results and determing if they will print ok?
    Bob

    The closest to a one click fix in photoshop cs-cs5 is
    Image>Adjustments>Shadow/Highlight or opening the
    image through camera raw and using the recovery slider.
    http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-765da.h tml
    MTSTUNER

  • Determining what metadata will get specific album art from iTunes Store

    How can I determine what metadata will get specific album art from the iTunes Store?
    e.g., I have some tracks with correct metadata for the album "International Herb" by the band "Culture".  This album is listed under the same artist & title in the iTunes Store, but getting the album art for these tracks results in an Artwork for "Culture - International Herb" could not be found warning message.
    Alternatively, is there some function where I can apply the album art for the album that I am currently viewing in the iTunes Store to tracks selected in iTunes?  (if this feature doesn't exist, it would be great if Apple added it)
    Thanks.

    I always thought it was just Artist + Album, but if the tracks are out of order or the durations are too different, it is possible that it is seeing it as a different version = no match.
    It will be faster to find the image from another source (thanks web search) and just drag or paste it into the Album Info panel.

  • HT1349 hi Mmm ive been told that installing linux on mac book pro retina 15 and even others and using it as my first sofware will make the mac heaqt up and burn from inside!!!!! true??????????

    hi Mmm ive been told that installing linux on mac book pro retina 15 and even others and using it as my first sofware will make the mac heaqt up and burn from inside!!!!! true??????????

    Hi shldr2thewheel,
         it has been a while since we have last spoke, I would like to let you know, I am still working on getting used to the switch from windows to a Mac/Apple system. I do have a new question for you, I did purchase In Design CS5.5 through journeyed.com through Cuyahoga Community College of which I attend as a student, is there a way to purchase an online book through iTunes to learn that as well? Also, you know me, the struggling student, I would also, when and if the book can be purchased through the iTunes, would need to know if you do know of a much easier book for struggling students like myself and at a reasonable price as well for the In Design CS5.5 program. Our campus bookstore had closed early, and, so did the colleges library and our local library here where I do live, so, I cannot go to either place to purchase a book or to take out a book, plus cash funds are low at this moment as well but, I do have money left on the iTunes account to use, if it can be used. So, can it be used, the iTunes money, towards finding a low priced online book? I am in great need of assistance as I have a project due for my one course for this Tuesday, September 4, 2012.
    Sincerely in need of help once again,
    Kim

  • Hi Mmm ive been told that installing linux on mac book pro retina 15 and even others and using it as my first sofware will make the mac heaqt up and burn from inside!!!!! true??????????

    hi Mmm ive been told that installing linux on mac book pro retina 15 and even others and using it as my first sofware will make the mac heaqt up and burn from inside!!!!! true??????????

    hi Mmm ive been told that installing linux on mac book pro retina 15 and even others and using it as my first sofware will make the mac heaqt up and burn from inside!!!!! true??????????

  • How do I determine what processes are running?

    I'd like to determine what processes are running on my iMac running Mtn Lion.  Is there an analog to Windows Task Manager?

    Open the Activity Monitor in the /Applications/Utilities/ folder.
    (76553)

  • Multi-threads will run better on multi-Processores environment?

    Are there any proof to say that Multi-threads will run better on multi-Processores environment?
    Will Java run better on multi-Processores environment? Are there any proof?
    Thank in advance

    Are there any proof?The proof is in the pudding, so to speak. The best thing to do is to benchmark your application on single and multi-processor machines.
    It should be noted that there are reports of threading problems with Java on multi-processor machines. I haven't seen the problems myself, nor do I remember the exact problems people were seeing (and on what OS/Hardware) but if you search these forums you should be able to find out the details.

  • Just updated to ios 4.3.2 and none of my IPhone 3Gs apps will run. The original apps that came with the phone do work though.  What do I have to do to get them working again?

    Just updated to IOs 4.3.2 and none of my IPhone apps will run.  The apps which came with the original phone do work though.  What can I do to fix this problem?
    Thanks,
    Brian

    Helfpul answers here:
    https://discussions.apple.com/message/13386937#13386937
    A restart sometimes works

  • Using javascript or HTML, When I click a link to a named page that already loaded in a tabbed page the tabbed page does not show, but you can see that the page relaoded. Using HTML or javascript what script will make this happen? The javascript focus() fu

    If a page is already loaded into a tab then using any of the following scripts will not cause the tabbed page to show when the link to it is clicked (created via PHP):
    "Continue Shopping".
    OR
    "Continue Shopping".
    OR
    "Continue Shopping".
    The first HTML works perfectly in the Safari browser.
    == This happened ==
    Every time Firefox opened
    == Always

    The scripts for this should have shown as:

  • If I turn off 3G and use the wi fi, does it still run on my data plan?

    I want to Figure out what data plan to get, and was wondering that if I could switch the 3G capabilities on and off daily, if that would help me save my data.

    If you use WiFi it does not count.

  • HT2494 Hi there my name is Peter i have a Mac OS X processor 2.66 GHz Intel Core i5.I would like to know if i could put my printer 25" from my computer and use a cable to join them, will this length of cable effect my Mac.

    Hi there, can i use a 25" printer cable with my computer. I have wireless internet but my mac will not recognize it since i changed routers with shaw.

    That should not be a problem. I would see if Shaw can't help you with your wireless. I'm on Shaw cable using their router, and my wireless works perfectly.
    One thing you might try after changing a router:
    Disconnect power from the modem, router, and computer. Wait at least one minute. Then reconnect power in this order:
    Modem. Wait until the status lights show communication with the host.
    Router. Wait until status lights show communication with the modem.
    Computer. Check that Network preferences are configured for DHCP, and it has a valid IP address.

  • Buy and use iPad 3 within 30 days will be exchanged for the iPad 4

    Good News for people who just bought ipad 3 within 30 days, Some Apple stores will apply exchange policy for ipad3 to get ipad4 .First store in San Francisco ! Let's call your Apple store and ask them ! Anyone knows this ?

    Good News for people who just bought ipad 3 within 30 days, Some Apple stores will apply exchange policy for ipad3 to get ipad4 .First store in San Francisco ! Let's call your Apple store and ask them ! Anyone knows this ?

  • I have a mac osx 10.3.9 and need to download firefox version that will run on it.

    I mistakenly downloaded firefox 3.6 before I realized my system wouldn't support it. Now firefox won't launch, and replaced my older firefox version in applications. Now what do I do?

    Firefox 2.0.0.20 is the last ever release for Mac OSX 10.3.9 and earlier versions. Get it here: <br />
    https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.20/mac/en-US/

  • What version will run on 1050 mhz athlon 2048 mbs ram

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [/questions/838186]</blockquote>
    XP pro
    Award ASUS A7M266 ACPI BIOS Revision 1007

    You need a Pentium 4 compatible processor with SSE2 support for Firefox 4 versions and later, so you need to check that.
    * http://www.mozilla.com/firefox/5.0/system-requirements/
    * http://www.mozilla.com/firefox/4.0/system-requirements/

  • Hi. I opened iPhoto and, suddenly, it tells me " WHAT IPHOTO LIBRARY DO I WANT TO USE?" but i had a iPhoto library. When i search on my Pictures, i have the file IPHOTO LIBRARY but it appears on a dim letters and i can not open it.

    Hi. I need some help on the following problem. I opened iPhoto and, suddenly, it tells me " WHAT IPHOTO LIBRARY DO I WANT TO USE?" but i had a iPhoto library. When i search on my Pictures, i have the file IPHOTO LIBRARY but is was not the icon on it i previously remembered and it appears on a dim letters and it can not be opened ... How can i recover it??

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

Maybe you are looking for

  • A few questions about Canvas and other Image related stuff.

    I am just starting to play around with Canvas in the hopes of using it to make a little game (not an applet) in my spare time. I have gotten a ball to bounce around the screen and switch colors when it bounces without too much work. (hooray for me!).

  • Set date as MM/dd/yyyy as in parameter for SQL Server stored procedure

    I have string date in MM/dd/yyyy . My requirement is to send date as in parameter to stored procedure in format MM/dd/yyyy . CallableStatement cstmt=null; cstmt = connection.prepareCall("{...... How this to be done .I am Using SQL server. If i do lik

  • Warning In Check DB

    Hello Guru's Vital Information About Server Database - ORACLE - 10.2.0.2.0 O/s - Windows NT - 5.2 SAP - Netweaver 04 - XI Server kernel Information - Patch Level - 129 I am facing problem in my production server. In DB13 - Check DB job we are facing

  • How to implement the Struts plug in concept in JSF

    Hi, In my application I need to preload some data and keep it in ServletContext. In the struts app, I could do the same using Plug-In. For doing the same in JSF, do I need to write the ServletContext Listener or does JSF has some wrapper classes to p

  • Ramdon image on page load

    Hi does anyone know a simple method of changing an image when a page is reloaded or refreshed?