How does Thread scheduling Work

Hi to all out there. I have been deweloping a program that is supposed to create a Sceduling Thread that would have the higest priorety and manage three more threads. The sceduler creates a CircularList class to call and run each of the other three threads.
Unfortunatly there are two errors that I can't trace down. If there is any one out there familiar with OS progming I would apreciate a few comments on the following code:
import java.lang.*;
public class TestScheduler
     public static void main (String args[])
          Thread.currentThread().setPriority(Thread.MAX_PRIORITY); //Sets Sceduler Priorety
          Scheduler CPUScheduler = new Scheduler();
          CPUScheduler.start();
/*creates The three other threads to be managed*/
          Thread t1 = new TestThread();
          t1.start();
          //CPUScheduler.addThread(t1);
          Thread t2 = new TestThread();
          t2.start();
          Thread t3 = new TestThread();
          t3.start();
class Scheduler extends Thread
     public Scheduler(){
          timeSlice = DEFAULT_TIME_SLICE;
//creates the queues for threads
          queue = new CircularLi();
     public Scheduler(int quantum){
               timeSlice = quantum;
               queue = new CircularList();
     public void addThread(Thread t){
               t.setPriority(2);
//Error 1 here. Can't recognize the .addItem() method?
               queue.addItem(t);
     private void schedulerSleep(){
               try{
                    Thread.sleep(timeSlice);
               }catch(InterruptedException e){};
     public void run(){
          Thread current;
          this.setPriority(6);
          while (true){
//Error 2 is here. It sais it can't find a method .getNext()?
               current = (Thread)queue.getNext();
               if ((current != null) && (current.isAlive())){
                    current.setPriority(4);
                    schedulerSleep();
                    current.setPriority(2);
     private CircularList queue;
     private int DEFAULT_TIME_SLICE = 100;
     private int timeSlice;
class TestThread extends Thread
     public void run()
          Total = 0;
          Total++;
          System.out.println("This ran for: " Total " times.");
     public int Total;
class CircularList extends Scheduler
     public void run ()
          Thread.currentThread().setPriority(5);
          while(true)
               if(Total < 5)
                    new TestThread().start();
                    Total++;
               else
                    Thread.currentThread().setPriority(2);
                    Total = 0;
     private int Total = 0;
Is there another library class I do not know about or do I have to write this methods myself?

Where have you got the CircularList from?
it is not part of the java API ... so who ever wrote it should be able to answer your question.
If it sticks to the conventions of the collection API
the method addItem is probably simply named add
and instead of queque.next() you use an iterator instead like this:
Iterator iter = queque.iterator();
while (iter.hasNext()){
Object o = iter.next();
// do something with o
HTH
Spieler

Similar Messages

  • How Does the scheduler works with ODI engine

    Hi All,
    I am new to the ODI and I was going through the documents over the web regarding the scheduling.
    Can anyone please let me know how does the Scheduler in ODI is coupled with the ODI engine.
    How does the internal scheduler works and how does the external one works. What are the processes the it calls while invoking the scheduler.
    Your help will be highly appreciated.
    Thanks,
    Sumit

    Scheduling in ODI is controlled by a special type of ODI agent, strangley called the ODI scheduling agent. This agent is installed as a service and as well as being responsible for all tasks associated with a normal agent is also responsible for managing ODI jobs based on any scheduling information associated with an ODI scenario. All scheduling information is stored in the ODI repository and the scheduler agent reads from this to determine which jobs/scenarios need to be executed and when.

  • How does thread.interrupt() work

    What I would like to do is cause an interrupt of the main thread in the Timer thread and catch the interrupt in the main thread, but the 'catch(InterruptedException)' in the main thread has an unreachable error. I am confused. The 'interrupted()' is not static and so I assume that 'thread.interrupt()' will cause and interrupt in 'thread', the main thread, but I can't seem to be able to catch it. Any idea what I'm doing wrong and how to fix the problem?
    public static Message receive(int milliseconds, BufferedInputStream in) {
        Message message;                         // Message return value
        class Timer implements Runnable {
            Thread thread;                       // Calling thread
            int    milliseconds;                   // Timeout in milliseconds
             public Timer(Thread thread, int milliseconds) {
                this.thread = thread;
                this.milliseconds = milliseconds;
            } // public Timer(Thread thread, int milliseconds)
            @Override
            public void run() {
                try {
                    Thread.sleep(milliseconds);
                    thread.interrupt();         // timer expired before input achieved
                } catch (InterruptedException e) {
                    // input received before timer expired
            } //  public void run()
        } //Timer implements Runnable
        if (milliseconds <= 0)
            message =  receive(in);
        else {
            try {
                Thread timer = new Thread(new Timer(Thread.currentThread(), milliseconds));
                timer.start();
                message = receive(in);
                timer.interrupt();
            } catch (InterruptedException{
                // Do something, in desperation if you have to.
        return message;
        } // Message receive(int time, BufferedInputStream in)
    }

    The current code has a 'Thread.interrupted()' in it, see below. Unfortunately, the if statement is never executed (crash and crumble). The code which actually input a message, something like
        BufferedInputStream in = read(header, 0, HEADER_SIZE);Won't let me put a try/catch statement around it, same reason - unreachable code.
    So where I'm at is that I don't understand what I have to do to do a thread.interrupt() and then catch it.
    public static Message receive(int milliseconds, BufferedInputStream in) {
        Message message;                         // Message return value
        class Timer implements Runnable {
            Thread thread;                       // Calling thread
            int    milliseconds;                   // Timeout in milliseconds
             public Timer(Thread thread, int milliseconds) {
                this.thread = thread;
                this.milliseconds = milliseconds;
            } // public Timer(Thread thread, int milliseconds)
            @Override
            public void run() {
                try {
                    Thread.sleep(milliseconds);
                    thread.interrupt();         // timer expired before input achieved
                } catch (InterruptedException e) {
                    // input received before timer expired
            } //  public void run()
        } //Timer implements Runnable
        if (milliseconds <= 0)
            message =  receive(in);
        else {
                Thread timer = new Thread(new Timer(Thread.currentThread(), milliseconds));
                timer.start();
                message = receive(in);
                timer.interrupt();
            if (Thread.interrupted() {
                // Do something, in desperation if you have to.
        return message;
        } // Message receive(int time, BufferedInputStream in)
    }

  • How does time machine work when being used with a mac pro?

    How does time machine work when backing up a mac pro?
    Considering the fact that the mac pro can hold 8TB and a external (non NAS) hard drive can hold only 2TB does time machine only backup the OS disk.

    macnewcomer22 wrote:
    Considering the fact that the mac pro can hold 8TB and a external (non NAS) hard drive can hold only 2TB does time machine only backup the OS disk.
    Time Machine will backup everything by default, on every disk in your Mac.
    Choose System Preferences > Options to exclude items. You could exclude everything except your OS...but I'd think it is your data that's more important to you, if you have to make choices.
    See...
    http://discussions.apple.com/thread.jspa?threadID=1964018
    While it's true you can store almost 8TB, how much do you think you'll actually store? If you have 1TB of data you want to store then a 2TB drive can do it. Also when your TM drive begins to get full it will begin deleting the oldest backups to make room.
    You could also get a Drobo with 8 bays...
    http://www.drobo.com/products/index.php
    -mj

  • How do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the onli

    how do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the online photoshop, and I really want to create my own customized url and post photos to my gallery and share them with the world, family, and friends, but i need help because i can't figure how to do any of this, would really appreciate feedback and assistance, thanks, - claire conlon

    To add to sig's reply, "calibrating" does not calibrate Lithiu-Ion batteries, it calibrates the charge reporting circuitry.  If you look at the effect of deep discharging Lithium-Ion batteries in the data from the independent test group, Battery University, you will see that doing so shortens the life of the battery significantly. It looks like an optimum balance between use and life is at a discharge level of 50%.

  • How does TimeOut(Sec) works/ behave in FTP Adapter?

    Hi ,
    How does TimeOut(Sec) works/ behave in FTP Adapter?
    Lets Say : If I mention 300 Secs in this . How Should it behave ??
    if a file processing in adapter is taking more then 300 sec , will it also be  terminated ??? what error response i will get in such case.
    Regards
    Prabhat Sharma.

    Hi,
    if there's a network error the channel may hang (for a very long time)
    if you specify 300 secs after that time the channel will reset the connection and you can start pooling again
    for more details:
    Note 849089 - XI 3.0 / PI 7.0 File Adapter: FTP Timeout Handling
    Regards,
    Michal Krawczyk

  • How does SAPscript 'WRITE_FORM' works ?

    Hi
    I have a Z program working fine, it is a SAPM07DR copy and i aggregated some fields to WASCHEIN form.
    But i see when the program (standard or copy) calls the write form, the field values in program have other values (just the previous values) than the values wich appears in the printed form.
    For example: 
    WASCHEIN KOPF Window has the WERKS value:
             Plant:    &*T001W-WERKS&
    But when the write form is called
              CALL FUNCTION 'WRITE_FORM'
                EXPORTING ELEMENT = 'KOPF'
                WINDOW            = 'KOPF'.
    In the program the *T001W-WERKS field has a different value that the value wich appears in the spool, debugging i see that the field has the prevoius value in the program:
    Program
    *T001W-WERKS
    (when Write Form).............Spool
        '     '...................................Plant:  0900
        '0900'.............................Plant:  0901
    I had to do the same logic in my new aggregated fields, but i realy don't know why does the program works in this way.
    Why the print program and sapscript function works in this way ?
    How does WRITE-FORM works, that is where the function take from the values to print ?
    Thanks
    Frank

    Hi Max
    I hope the program works like you said, but it works:
    old_werks = '   '
    T001W-WERKS = '0900'.
    *T001W-WERKS = T001W-WERKS .
    *T001W-WERKS = old_werks.    <-- '   '
    CALL FUNCTION 'WRITE_FORM'
    (form KOPF with *T001W-WERKS)
    old_werks = '0900'
    T001W-WERKS = '0901'.
    *T001W-WERKS = T001W-WERKS .
    *T001W-WERKS = old_werks.    <--  '0900'
    CALL FUNCTION 'WRITE_FORM' 
    (form with *T001W-WERKS)
    But the FM prints 0900 and after 0901, when the *T001W-WERKS values were '    '  and  '0900'   !!!
    (and with the *T001W-NAME1 field occurs in the same way)
    Why does the FM prints that values ??
    Thanks
    Frank

  • How does Merged Dimensions Work in WebI created on SAP BI Queries

    Hi,
    I need to know how does Merge dimensions work in WebI when using SAP BI Query as source?
    Below is my understanding when connection is defined for the universe on oracle database:
    1) To get the data in merged dimensions, there must be physical join (Either Direct or vai some other tables) between different tables at backend level (This means  there  must be join between tables in Oracle database.)
    2) we get the UNION of data when dimensions are merged at webI level.
    I dont know how this works in SAP BI.
    Since there is different data model defined for different BI Queries in SAP , and for each BI Query and there is seperate Universe, So how can you get correct data in WebI when there is no connections in DSO's used in different BI queries?
    Can any one suggest me the way data apperas in merged dimensions for WebI created on SAP BI?

    I assume we are only talking about merging dimensions in Web Intelligence here and not on the BW backend. this is a client side mere where you have 2 resultsets.
    if you want to do this on the BI server side it would be a multi-provider combining different InfoProviders - or a InfoSet - depending on the join type you need. MultiProvider is a union, Infoset allows you to choose
    Ingo

  • Transfer Rules: How does the mapping work?

    Transfer Rules: How does the mapping work?
    Is there a document out there that explains the following or can someone help clarify it for me. I have some confusion on what is really going on.
    When I create an InfoSource (IS_Test)  as a “Flexible update…”  and then “Assign DataSource”  (DS_Test) and I respond Yes, to the message “DataSource assignment DS_Test to InfoSource IS_Test Save”
    a) <b>Under “Transfer_Structure/Transfer_Rules”</b> in the InfoSource
    1)  the “Transfer Rules” tab, what are the fields found in the right column (Assigned InfObjct-field)? And where do the fields you enter in the left column (<b>Communication Str/</b>Transfer rules) eventually go?
    2)  the “DataSource /Trans. Structure” tab, can I always assume that all the fields in the right column (DataSource) came from DS_Test? The left column (Transfer Structure), in my test was exactly the same as on the right. Where do these fields eventually go?
    b) Under “<b>Communication_Struct.”,</b> in the InfoSource
    3. the right column (ISource Fileds) where from those InfoObjects. if I am now creating my InfoSource. Where did they come from?
    4. The left column is “<b>Communication Structure</b>”, which at this point has no InfoObjects, if I move a couple of InfoObjects from the right to the left, where do these Objects in the left eventually go?
    5. what is the relationship between the “Communication Structure” in 4 and 1? Or any relationship between a) and b) as a whole?
    Thanks.

    Hi Caud,
    As Ashish pointed out, communication structure contains fields (infoobjects) that suppose to go to data targets. Which IO in CS to which IO in the data target will go (and what transformation of data may occur) is determined in URs of the data target.
    The transfer structure is the structure in which the data is transported from the source system into BW:
    http://help.sap.com/saphelp_bw33/helpdata/en/3f/0e503c3c0d563de10000000a114084/frameset.htm
    In “Transfer_Structure/Transfer_Rules” in the IS, DataSource /Trans. Structure” tab, right part shows fields in the Datasource, the left part – fields in the transfer structure. There is also a transfer structure in R/3 for a given DS. Transfer structure in BW is created identical to the TS in R/3 during TRs activation.
    During data load data are transferred 1:1 from TS in R/3 to TS in BW.
    TS in BW corresponds to the PSA table structure.
    How data from PSA are transferred to the CS is determined in TRs.   
    The 3rd column (“Field”) (“Transfer Rules” tab, right part (Assigned InfObjct-field)), contains field names of the DS (TS); and the 1st column shows IO in the CS to which the DS field will go. So, it’s a mapping DS filed -> CS field.
    The left part (“Communication str./Transfer rules”) is always identical to the CS content. But the 4th column (“Tp”) shows possible data transformation during transfer from PSA to CS. If this column contains a yellow triangle then there is no transformation (Value of DS field will go to value of CS field). If there is a red cross, it means that no data for this CS field is supplied from a DS. You can click on this yellow triangle and choose: 1). Another field from a DS; 2). Constant; 3). ABAP routine; 4). Formula. So, here you can determine the data transformation. Moreover, there is a possibility to create a start routine (blank sheet icon at the top).
    And finally, here are the answers on your questions:
    Q:
    a)     Under “Transfer_Structure/Transfer_Rules” in the InfoSource
    1) the “Transfer Rules” tab, what are the fields found in the right column (Assigned InfObjct-field)? And where do the fields you enter in the left column (Communication Str/Transfer rules) eventually go?
    A: Right part shows a mapping between DS and CS fields. Left part shows CS fields and data transformation (TRs) during data transfer from TS (PSA) to the CS. These are fields in the CS that will go to data target and which are fed from a TS (DS).
    Q: 2) the “DataSource /Trans. Structure” tab, can I always assume that all the fields in the right column (DataSource) came from DS_Test?
    A: Yes, you are right.
    Q: The left column (Transfer Structure), in my test was exactly the same as on the right. Where do these fields eventually go?
    A: As I described, left and right parts are identical. These fields will go to CS.
    Q: b) Under “Communication_Struct.”, in the InfoSource
    3. the right column (ISource Fileds) where from those InfoObjects. if I am now creating my InfoSource. Where did they come from?
    A: these are fields from an IS template, the name of this template you can see above this right part.  Actually, during IS (CS) creation you can choose different templates and choose fields from them transferring them into the left part.
    Q: 4. The left column is “Communication Structure”, which at this point has no InfoObjects, if I move a couple of InfoObjects from the right to the left, where do these Objects in the left eventually go?
    A: these are fields of CS (left part) and as I said before they will go to data target.
    Q: 5. what is the relationship between the “Communication Structure” in 4 and 1? Or any relationship between a) and b) as a whole?
    A: CS in 4 just shows IOs that will be transferred to data target. CS in 1 also shows how values for CS IOs are to be fed and transformed.
    Best regards,
    Eugene
    Message was edited by: Eugene Khusainov

  • KPI -How does the periodicity works in SM

    Periodicity is @ Context level only? That means we have to define different contexts for weekly &monthly? That doesnu2019t fly good
    How does the periodicity works in SM..data entry as well as frontend display?

    Hi TR,
    When looking at a scorecard, you should see the status for all objectives and KPIs during the same time period. If you look at Revenue KPIs for just one week and Cost KPIs for the whole month, how can you assess how you performed in that month?
    This doesn't mean that the metrics in PAS cannot have different periodicities. They can! But when looking at data in the scorecard these periodicities will be converted to the scorecard periodicity. For example if you have monthly metrics and you are looking at scorecard data quarterly, the scorecard will show you the value for the 3 months of that quarter. Here, you should take care to define the proper time consolidation properties for the metric (it can be SUM, like in costs or revenue, AVERAGE, LAST, FIRST...).
    Likewise, if you have quarterly metrics and you want to see scorecard data monthly, then PAS does a breakdown of the value per months.
    Anyway, if you are looking to setup a weekly scorecard, that will likely include a different set of metrics that a monthly scorecard would. Weekly scorecards will problably include more operational metrics and will lack the strategic focus of scorecards with a broader time scope.
    Regards!
    Ricardo

  • How does SUM actually works

    Hi,
    I'm puzzled by how SUM actually works.
    I've got a table with the following fields:
    SET_OF_BOOKS_ID NOT NULL NUMBER(15)
    SUMMARY_CODE_COMBINATION_ID NOT NULL NUMBER(15)
    DETAIL_CODE_COMBINATION_ID NOT NULL NUMBER(15)
    TEMPLATE_ID NOT NULL NUMBER(15)
    LAST_UPDATED_BY NOT NULL NUMBER(15)
    LAST_UPDATE_DATE NOT NULL DATE
    ORDERING_VALUE NOT NULL VARCHAR2(25)
    Using the below, I was able to get the total value of all the ordering value.
    select sum(ordering_value) from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    I was happy that I could get the total value but am puzzled as ordering value is of data type VARCHAR2.
    Is sum(ordering_value) a VARCHAR2 or a NUMBER then?
    I did a simple test, inserting the following record:
    insert into gl_account_hierarchies values(1,1024,1,2,3,'11-APR-2002','xyz');
    After committing, I double check by using the following statement:
    select * from gl_account_hierarchies where last_update_date = '11-APR-2002';
    and was able to retrieve the newly inserted record.
    But when I did another check with the following statement:
    select * from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    I wasn't able to retrieve the newly inserted record.
    Why is that so? How does SUM actually works? Is the output of SUM a VARCHAR2 or NUMBERIC value?
    thanks in advance!!
    Yu S.S

    SUM() gives a number.
    What you have come across is an implicit data conversion. Basically the SQL parser doesn't reject your query as being syntactically invalid just because you're attempting a mathematical function on a non-numeric column. Instead when you execute your query SQL substitutes this
    select sum(to_number(ordering_value)) from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    If you want to check this create a view
    create order_value as select sum(ordering_value) sum_val from gl_account_hierarchies ;
    and then desc it.
    Cheers, APC
    SUM(

  • How does request.setAttribute() works?

    How does request.setAttribute() works?
              Does it append data to http header and forward? Does it set to a memory
              space like session.setAttribute() does?
              Thank you
              Jim
              

              Q. Does it append data to http header and forward?
              No.
              Q. Does it set to a memory space like session.setAttribute() does?
              Yes. So you can set attributes in request scope and use them in the servlets and
              JSPs in the servlet chain via request dispatcher and jsp:include/jsp:forward.
              "Jim" <[email protected]> wrote:
              >How does request.setAttribute() works?
              >Does it append data to http header and forward? Does it set to a memory
              >space like session.setAttribute() does?
              >
              >Thank you
              >Jim
              >
              >
              

  • How does at NEW works?

    Hi,
    How does AT NEW works with the below code>
    LOOP AT i_crhd into x_crhd.
    at new arbpl.
    v_resource = x_crhd-arbpl.
    LOOP AT i_afko into x_afko.
    at new plnbez.
    v_matcode = x-afko-plnbez.
    READ TABLE i_mseg into x_mseg with key x_afko-aufnr.
    IF sy-subrc eq 0.
    IF x_mseg-bwart eq '101'.
    v_menge_101 = v_menge_101 + x_mseg-menge.
    ELSEIF i_mseg-bwart = '102'.
    v_menge_102 = v_menge_102 + i_mseg-menge.
    ENDIF.
    ENDIF.
    endat.
    ENDLOOP.
    endat.
    ENDLOOP.
    Thanks a lot!

    Hi,
    In your program....
    For every new arbpl AT NEW will trigger and for eveery at new plnbez one more new field will trigger.
    Ex:  We have below records in your internal table 'i_crhd'.
    arbpl
    101
    101
    102
    103
    103
    and  we have records in internal table 'i_afko '
    plnbez
    A
    A
    A
    B
    B
    C
    C
    For every change in arbpl record AT new will fire and for every cheange in plnbez one more AT new will fire.
    Pls. reward if useful...

  • I wanted to know how does technical support work via icloud and is there any new technology out that helps providing technical support

    i wanted to know how does technical support work via icloud and is there any new technology out that helps providing technical support?

    basically I’m doing a project were I wanted to find out if there are recent technology  out that provides technical support for example they do it with remote access but is they any new ways that  they can support us and just wanted to find out if icloud gives technical support then how?

  • How does chat applet works?

    how does chat applet works? What specific technologies should i learn to make a chat messaging work?
    thanks in advance for ur help...

    Chat applets work on sockets. Normally there are two parts. One server and one or more clients. The clients connect to the server and any message sent by a client is then distributed by the server to all the other clients.
    Sun's site is incredibly slow tonite so I'll give you a google link
    http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=chatserver+chatclient+java

Maybe you are looking for

  • Opening Balances and Closing Balance of customer

    Hi, Does SAP provide any standard customer account statement for Opening Balances and Closing Balance for specific date range have given in selection screen? The statement also contains reference number, order, and Delivery number. Note: FBL5N Transa

  • Keynote Export to PowerPoint

    Well, I was using this work around just fine, until I upgraded to Office 2008. http://discussions.apple.com/thread.jspa?threadID=1341613 Now I can't even open that PowerPoint file at all. I get the error in PowerPoint that it experienced an error and

  • 10.5 compatibility mode on 10.6

    I need to run 10.5 on my imac, I currently run 10.6.8, is there any way to do it? I bought a belkin router and the software doesn't run on 10.6!!

  • Time machine backup is missing from WD_Backup folder!

    Hello, I have a MyBook World Edition 1TB that i am using it for time machine, the WD_Backup folder ( in Mybook ) is empty but when checking the MyBook webpage it's saying 80% ( around 900 GB ) of the HD is used!, like the data is there but i cant see

  • Rotoscoping With Pen Tool

    Hello Everyone. I am using the Rotoscoping using the Pen Tool. I have used the Pen Tool for many years with Photoshop,  Inside Photoshop when I Draw a path over a Selection, I use the Alt-key at the end of each path, to Draw more Paths. I have notice