Help needed about thread priority

Hello, could someone help me with the priorities in java? I got 10 levels in total(1-10), but I do need at least 20 levels for my multiple threads program.
Thank you for your kind help in advance.

First, let me apologize if I am incorrect, but it seems that the native Thread implementation restricts you to 10 priorities regardless.
However, you can do just about anything you envision, but it will require some implementation on your part.
You could implement a subclass of thread that contains your priority (which could be from 1-20). You could then maintain a ThreadManager that would store all running threads, and would accept requests to start and stop threads. The ThreadManager could make decisions about which threads to run, which to interrupt, which to sleep, etc., based on your priority value.
This sounds like alot to swallow, but I'm sure it's doable if you understand threads.

Similar Messages

  • Help needed about Java Threads ?

    Hi,
    I have a p2p java program that contains many classes, A.java, B.java, etc. It works fine when i send or recieve to eachother one at a time, but I would like to be able to send/recieve things at the same time. So i would probably need to use Java Threads. Can somebody please show me how this is done. I would really appriciate it. Thanks!!
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    public class A {
            private static String hostname; //host name
            public A () { }
           public static void send() throws IOException {
                    //send code here
            public static void receive() throws IOException{               
                    //receive code here
            public static void main(String args[]) throws IOException {
                    //do both send/recieve at the same time?
                    send();
                    receieve();
    }

    Well, I think( this is comming out my rear ) that the scope of the recieve() call is not in the main method anymore but instead in class you've created with "new Thread()" and it's throwing from the public void run() instead. This is a good example of complicated code. I would do this:
    (Untested code)
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    public class A implements Runnable { // <--- NEW
            private static String hostname; //host name
            public A () { }
            public static void send() throws IOException {
                    //send code here
            public static void receive() throws IOException{               
                    //receive code here
            public static void main(String args[]) throws IOException {
                    //do both send/recieve at the same time?
                    new Thread( this ).start();
                    send();
            /******** NEW ************/
            public void run()
                while( keepListening )
                    // It's the assumption that recieve() is
                    // throwing the IOException from some net calls
                    try {
                       recieve();
                    } catch( IOException ioe ) {
                       System.out.println( "IOException in run()\n" + ioe.getMessage();
    }

  • Questions about thread priority...

    Situation 1) setPriority(int adsa)
    public class ThreadPrioDemo1 {
          static class Demo1 implements Runnable{
          public void run(){ //blablabla}
         public static void main(String[] asdf){
              Runnable r = new Demo1();
              Thread myThread = new Thread(r);
              Thread mainT = Thread.currentThread();
              //mainT's priority is 5, so as myThread.
            mainT.setPriority(10);
    //mainT's priority to MAX, this simultaneously changes myThread to 10 as well.
            //or
            myThread.setPriority(10);
    //myThread priority to MAX, however, this does not change mainT to 10
    }Question 1), why if main Thread is set to a certain priority, the thread it creates automatically change its priority to the same as well, but the reverse is different??
    Situation 2) this is slightly more complex
    public class ImplementingRunnable {
         public static void main(String[] args) {
         Thread mainT = Thread.currentThread();
              for(int ii=0 ; ii<args.length ; ii++) {
                   Runnable r = new MyRunnable(args[ii]);
                   Thread t = new Thread(r);
                t.setDaemon(true);
                //t.setPriority(Thread.MAX_PRIORITY);
                   t.start();
    }and
    public class MyRunnable implements Runnable {
        public void test(){
        System.out.println("test");
         String message;
         public MyRunnable(String msg) {
              message = msg;
         public void run() {
              Thread me = Thread.currentThread();
              try {
                   for(int ii=0 ; ii<10 ; ii++) {
                       //case (1) me.setPriority(Thread.MIN_PRIORITY);
                        me.sleep(3);
                        System.out.println(message);
                        //case (2) me.setPriority(Thread.MIN_PRIORITY);
              } catch (InterruptedException ie) {
    }In class ImplementingRunnable, how is the commented code line related or counter-related with the commented case 1 code line in MyRunnable??
    Please help
    thanks

    Let me speak my question again very simply:
    1)
    Say I have two threads, 1 is main() thread, the program entry point, 2 is another thread created by main().
    Now, the default priority for both two is 5. If I change the priority for main() to a certain level, the other thread created by it automatically change its priority to the same level? why? and however, the reverse (in this case, if I change the priority for the thread created by main()) is not.
    2)
    public class Demo{
    static class MyThread implements Runnable{
    public void run(){//some thing}
    Thread t = new Thread(this);
    t.setPriority(10);
    public static void main(String[] afd){
    Runnable r = new MyThread();
    Thread t1 = new Thread(r);
    t1.setPriority(1);
    }What can you say about both bold code lines?
    If I use println() to track the Priority, the final priority, that is, t1, is 1. It is logical, however, the program behaves differently without the bold code line in the static class MyThread, despite the final priority for t1, is the same, 1.
    Any help by now??
    thanks alot

  • Help needed on threads!!!

    Hello All,
    Following is the scenario that I'm trying to do.
    Thread_A: puts the data/messages into Queue A (I'm using linked list as the data structure)
    Thread_B - pulls the data/messages out from Queue A .
    So far I have implemented the following
    Class A implements Runnable
    {   LinkedList  queue A  = new LinkedList ();
    Thread_ A = new THread (this)
    Thread_A.start();
    run{
    Putting the messages into QueueA;
    classB.copyQueue(queueA); //this method is defined in classB
    Class B implements Runnable
    {   LinkedList  queueB   = new LinkedList ();
    Thread_ B = new THread (this)
    Thread_B.start();
    copyQueue(linkedList A){
    queueB = A;
    run{
    pull the messages from QueueB;
    I hope I have explanined it clearly. . Is my design approach ok so far.? somehow I don't get that feelng. THought I will consult the experts. I'm new to java. Please excuse me if this is a silly question. Please help.
    Thanks.

    Well, there's no reason for each class to have it's own reference to the queue, for a start. Simpler to give B a reference to the instance of class A.
    You need to guard the access to the queue with synchronized and use the wait/notify methods to make threadB wait if the queue is empty.
    Easiest to stick a pair of syncrhonized methods into class A like:
    public synchronized void addToQueue(Object item) {
         if(queueA.isEmpty())
             notifyAll();   // if queue was empty wake the consumer thread
         queueA.add(item);
    public synchronized Object takeFromQueue() throws InteruptedException {
        while queueA.isEmpty()
           wait();
        return queueA.removeFirst();
         }Thread B calls takeFormQueue to get each item, which will cause it to wait until there's somthing to take.

  • Form help needed- creating a PRIORITY FIELD

    I cannot figure this out as i have looked all over the
    internet to no avail.
    I have a 30 question coldfusion flash form.
    I would like the user to select their top eight questions by
    having a drop menu labeled 1 thru 8 beside each question.
    The priority number can only be chosen once.
    Help please...

    zoemayne wrote:
    java:26: cannot find symbol
    symbol  : method add(java.lang.String)
    location: class Dictionary
    add(toAdd);this is in the dictionary class
    generic messageThat's because there is no add(...) method in your Dictionary class: the add(...) method is in your WordList class.
    To answer your next question "+how do I add things to my list then?+": Well, you need to create an instance of your WordList class and call the add(...) method on that instance.
    Here's an example of instantiating an object and invoking a method on that instance:
    Integer i = new Integer(6); // create an instance of Integer
    System.out.println(i.toString()); // call it's toString() method and display it on the "stdout"

  • Help needed about Xorg.

    Hi guys.
    I'm became really confused about this xorg.
    I would like to get my videocard working 100%
    I'm about to build a Mediecenter, and got and hauppaugePVR 500 - But that's only for recording the TV ??? or is it also for wieving tv?
    I have also a normal graphiccard with S-video out on. Wich one of these shold be connected to the TV. When I used the normal card - there's a lot of interference/stribes on the screen.
    But is it made that you also use the Hauppauge to watch tv on?
    And how do I configure xorg to handle the tv-out. I've look in other threads about this - but have not figured it out . Can someone please tell me more.

    peque wrote:And how do I configure xorg to handle the tv-out. I've look in other threads about this - but have not figured it out . Can someone please tell me more.
    Maybe this xorg sample helps:
    http://people.os-zen.net/shadowhand/configs/xorg.conf

  • Help needed about using wifi

    Please can somebody tell me in words of one syllable exactly what I need to start using an ipad for surfing the internet?  I want to use it to access web pages while I'm out and about.  Do I need a contract with a phone carrier?  Does it need to be a mobile phone carrier?  Could I use my landline number if I have broadband access on that?
    I just can't work out whether I can use the ipad straight away without doing anything or whether I need to involve a mobile or landline/broadband supplier.
    Please help - I'm soo confused.

    a Local area network also called LAN network is what most people use in their house
    it's cables you connect 1 or more computers to get Internet and  access files from eachother
    wifi id 100% that!
    just without the cable
    you have wifi router with a password on
    you go into the settings on the ipad and choose the wifi router name on the list and type in the password
    and you're able to go online
    if you are not within reach of your wifi network you need to reply on public wifi networks if any are aviable where you are at the given time some would be free some would require you to pay them for service
    you only need to contact a phone carrier if you don't wish to use wifi because you have an ipad which along side wifi support 3g internet then you need to contact a carrier and get a micro sim and a contract
    if you already have an mobile phone which qualify as a smart phone you may be able to use that as a wifi hotspot to get on the internet using the phone but in some places this require you to pay extre to your phone contract

  • Help needed in threads

    hi,
    Iam using the stop() from the API.But since it is deprecated I dont want to use it.Is there any way by which I could replace it ?I need to make changes in thousands of files.
    Any sample code for avoiding stop() wud be of immense help.

    Slightly at a tangent, but why
    while (true) {
    synchronized (mutex) {
    if (running) {         
    //execute some task
    mutex.wait(500);
    } else {
    break; //will break from while(true) loop
    }instead of
    while (running) {
    //execute some task
    synchronized(mutex);
    mutex.wait(500);
    Often VM's interpretation of what volatile means can differ from each other and it is my experience that in the past various VMs have been buggy with volatile variables. Hence to be doubly sure I want to ensure that access to the "running" variable is synchronized.
    synchronized (mutex) {
      while (running) {
        //execute some task
        mutex.wait(500);
    }is equivalent to my code above of course and I could (should) have used this. The reason is that I did a cut-and-paste job with some hasty alterations where for various reasons I wanted to re-do a check before waiting and also cede the mutex inbetween executing the task and waiting. Apologies for any confusion.
    The reason I ask is that I've never found a use for
    "break".I'm not mad-keen on it either as it isn't very good practice IMHO but it was quite useful where I have used it.

  • Help needed about Nearline storage in BW 3.5.

    Hi Guys,
    Can you please provide me with some documents for implementing Nearline storage scenarios in BW 3.5.
    Thanks,
    Punkuj...

    Hi Punkuj,
    We use Nearline storage to store the data that is never been user or used very rarely.For example we have data for year 1960 in the data targets and now it is 2007.So mostly the management never uses this data or they uses them very rearly.So when we retrive the data from the data targets the DB unnecessarly reads the data every time when a report is generated on those targets.So to avoid this performance issue we store that kind of data in a seperate disk and we access that data using a multi provider when we need that in Report.This data is also known as Dormat data.
    Hope this will help you.
    Thanks and Regards
    SandeepKumar.G

  • Help needed about JSTL

    We have tomcat server, in which we are running some jsp files( which consists some bean classes). We want to convert those bean classes into jsp tag libraries.Even we have installed jakarta tag libraries , but we are unable to run jstl files. Help wanted urgently.
    ThanX in advance.

    Your note has two problems in it: (1) Custom tag libraries of your own making, and (2) Running JSTL. I'd like to address the second of the two.
    I'm not sure what you downloaded from Jakarta. I'll assume that you're using JSTL 1.0.3 standard JSTL. (That's what I'm using.) The ZIP file I downloaded has a lib directory with 10 JARs in it. You'll need to put all 10 of them into your WEB-INF/lib directory for your app to use them.
    You don't have to put a <taglib> in your web.xml, and you don't need to dig out any TLD files. The TLD files you need are already inside the standard.jar that you downloaded with the JSTL. You should not be trying to re-create what is already correct.
    The pages that use the JSTL should have a tag like this near the top:
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>The uri attribute value must match the value in the c.tld file located inside standard.jar exactly:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
      PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
      "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
      <tlib-version>1.0</tlib-version>
      <jsp-version>1.2</jsp-version>
      <short-name>c</short-name>
      <uri>http://java.sun.com/jstl/core</uri>
    <!-- etc. -->MOD

  • Help needed about regex usage.

    hi all,
    i am kind of new to java.util.regex, and i can't solve this problem:
    i have a big string, that actually represents the text code of a method. in this method, i have an object, called, let's say "visitor" and i call several non static methods of it. i need to search this string and put into an ArrayList<String> all the occurrences of visitor, the method called, and its parameters.
    if i wasn't very clear, here is an example:
    the input string: "public void test_add()
              TemplateTestMethodVisitor visitor = new TemplateTestMethodVisitor(XMLArrayListTest.class);
              XMLArrayListComparer comparer = new XMLArrayListComparer();
              while(visitor.moveNext())
                   fillArrayList(visitor);
                   Exception exception = null;
                   try
                        _testedArray.add(visitor.getParameterAsInt("position"), ValueFactory.getMemberValue(visitor,
                                  visitor.getParameterAsString("type"), "ElementValue"));
                   catch(Exception e)
                        exception = e;
                   ExceptionValidator.validateException(visitor, exception);
                   if(exception != null)
                        continue;
                   VisitorAssert.assertEquals(visitor, "The content of the array list is not as expected.",
                             visitor.getResultAsCollectionData("List"), _testedArray, comparer);
    and i need to obtain an ArrayList<String> with {"visitor.moveNext()", "visitor.getParameterAsInt("position")" , "visitor.getParameterAsString("type")", "visitor.getResultAsCollectionData("List")"}. and it would be very helpful for me to do this using regex, but i can't think of a right pattern...
    thank you all.

    import java.io.*;
    import java.util.regex.*;
    public class TestRegexp {
      public static void main(String[] argv) {
        Pattern p = Pattern.compile("visitor\\..*?\\(.*?\\)");
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            Matcher m = p.matcher(line);
            while(m.find()) {
              System.out.println(m.group());
        } catch(IOException e) {
          e.printStackTrace();
    }

  • Help needed about Financial 11i installation

    Hi
    i m try to Install Financial 11i my stand alone PC.i m using Windows Xp with services Pack 2 & install all need software . i m getting error any one help me how can i remove that errorss.
    command : cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\adchkutl.cmd D:\cygwin\bin D:\v98
    There was an error while running the command - cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\adchkutl.cmd D:\cygwin\bin D:\v98
    'F:\Uninstall' is not recognized as an internal or external command,
    operable program or batch file.
    RW-50011: Error: - System Utilities Availability test has returned an error: 1
    MtierInfoPanel
    command : cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\checkOS.cmd
    There was an error while running the command - cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\checkOS.cmd
    'F:\Uninstall' is not recognized as an internal or external command,
    operable program or batch file.
    RW-50011: Error: - Operating System patch/version test has returned an error: 1
    O/S User and Group Check
    command : cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\adchkutl.cmd D:\cygwin\bin D:\v98
    There was an error while running the command - cmd.exe /c F:\Uninstall Oracle Financial\Stage11i\startCD\Disk1\rapidwiz\bin\adchkutl.cmd D:\cygwin\bin D:\v98
    'F:\Uninstall' is not recognized as an internal or external command,
    operable program or batch file.
    RW-50011: Error: - System Utilities Availability test has returned an error: 1
    RW-10001: Rapidinstall wizard has detected that your configuration has errors. You must resolve these issues before continuing.
    Returning to wizard after Install Check Failed warning.
    Thanks
    Rizwan Shafiq

    Do not use any directory name which contains spaces (i.e. F:\Uninstall Oracle Financial). Change the directory name to be (F:\Stage11i), clean up your previous installation and start over again.
    The same thing is applicable to (VC++, MKS, Cygwin ..etc)
    It should work then.

  • Help needed about x200s

    Hi people, I want to buy a x200s CTO in Australia. I don't like the ugly line on top cover of the machine. Also I want LED. I called the Lenovo Australia. They told me that every machine except SL has next generation roll cage and the x200s has the ugly line. It does not have the LED, even for the wxga+ panel.
    Can anyone tell me whether they produce different x200s? I mean in US, they have LED, Next Generation ThinkPad Roll Cage technology utilizes a carbon-fiber/ glass-fiber top cove, etc. But they sell different machines in Australia?
    I am confused. Hope someone can help me.
    Thanks in advance!

    Thanks, I really appreciate your contribution.
    Must the IPsec licenses be from cisco? Can I use openVPN licenses? The design will be hub and spoke because the be5000 will seat in HQ but the operation will be a mesh operation where the branches can also call each other using VoIP.
    There will be 20 SIP6941 IP Phones in HQ and 6 each in all the six branches.
    The PSTN connectivity if via FXO in all sites. 8 PSTN lines via FXO in HQ, 4 each in branches via FXO
    I have looked at be5000 and it fits my application more than be3000. the total number of IP Phones is 56. I think using 2900 series ISR makes things less cumbersome at the branches.
    Please I need to know if i am limited to using cisco ipsec vpn or i can use openVPN (my choice).
    Many thanks for your help and timely advice. I appreciate it.
    regards

  • Help needed about PDF - java

    Hi everybody,
    I just need to know if it's possible (and has been done already :) ) to take a pdf file and, using java, extract all the text boxes of it so that I can then be able to position them in a java application layout (using Swing).
    I need to do that to extract all the information of the text:
    - size of the page
    - position of the text box
    - size of the text
    - font
    - color
    - other attributes
    That's a subject that has already been discussed a lot, but I couldn't find a clear answer to that question in the forum.
    I really need your help, because I already spent a lot of time searching for that, and now I start wondering if it's really possible...
    Thanks a lot in advance for your help.
    Myriam.

    Hi Carlosbenfeito!
    Thanks a lot for your answer!
    I don't know if the pdf document is a pdf form... The only thing I know is that the pdf file I will have to extract the data from will be generated from a Quark document...
    I will try to find out more.
    In the same time, do you know where exactly I can find this Adobe jar? I had a look on their website, but I didn't find it...
    Thanks for your help.
    Myriam

  • Help needed about database xtra

    hi!
    I need to know a best Database Xtra which i can use for MS
    Access database or SQL Server database and which works for MAc as
    well as Windows OS.Please also let me know how do i plug in a step
    by step information and also how to use the methods of Xtras.
    Please help me regarding this.
    Thank you all in advance.
    MS Access

    I'm not sure if its 100% compatible with SQL server database
    but Valentina database xtra is the best
    its also the fastest. But it uses its own database file
    format and allows you to run SQL queries pretty good.

Maybe you are looking for

  • Can I get a refund for an app that my cousin got on accident

    My cousin was playing with my macbook and he bought this app called songwriters pad he wanted but it was my account i have no purpose for use for this application.. Please help.

  • Error in displaying a webi report

    We are getting an error RWI 00317 when trying to display a webi report within a .net application. When searched in the net, RWI 00317 occurs due to the reason that xalan.jar is missing... But that is for a java application. What is the similar soluti

  • I have restored my iPhone 4 S but iTunes is still trying to restore it. What do I do?

    I have upgraded my iPhone 4 to a 4S and have all afternoon been trying to restore it with my old iPhone backup.   I connected it to my computer and it did it straight away - I have all my contacts and texts up until monday morning however I have none

  • Sending large amounts of data spontaneously

    In my normal experience with the internet connection, the bits of data sent is about 50 to 80% of that received, but occasionally Firefox starts transmitting large amounts of data spontaneously; what it is, I don't know and where it's going to, I don

  • Changed from Windows lap top to iMac - and can't sync my iPod

    I can't get my iPod to sync with my new iMac - it still only recognises the original Windows lap top. I still use the lap top, but have copied my itunes across to the iMac and plan to use this as my main machine. How do I get the iPod to accept the M