Thread Scheduling Query

Hi,
If i have 3 messages A, B and C which are in a queue and are to pass through a synchronized method Y . A particular thread X picks 1 message each from the queue and spawns a thread for each of 3.
A is executing Y and B and C are in BLOCKING State and waiting for A to finish so that they can enter Y.
Is it possible that C executes first before B.
Pls advice.
Thnx in Adv
Amandeep

Setting a thread's priority is not the preferred solution namely because it is dangerously inconsistent. The only time to use thread priority is when you have tasks that do not have scheduling conflicts like this and you really don't care when a particular thread runs. As an example the garbage collection thread in a VM is normally a lower priority thread until such time that garbage collection is needed.
The preferred solution for thread scheduling and order of executing issues is to revisit the design.
In the example given by the OP I would first question the use of multiple threads at all. It seems that the OP wished tasks to be executed from a queue in the same order as they were added to the queue and that tasks later in the queue should not finish execution before ones earlier.
This does not seem a good use for multiple threads because this requirement seems to call for anything but parallel execution.
But perhaps I am reading too much into that statement. I would suggest a revist of the design though to look at doing the following.
Launcher thread
1) Gets next thing from queue
2) Calls synchonized Y method (that no longer needs to be synchronized probably) using thing from queue
3) Starts new thread with results from Y
4) Go back to 1
This design garauantees at least that the launcher threads will be started (and past the synchronized method) in the same order as they were received.
Does that mean they will complete execution in the same order? No. Does it mean they will actually start processing in the same order? No. But it does mean they will call Y in the same order and since I would guess that is the real issue here it solves the problem.
If the threads really must finish in the same order than one must consider either; not running seperate threads as I mentioned earlier or adding a semaphore at the end of the spawned "worker" threads so that they wait for previous threads to finish before exiting.

Similar Messages

  • IS a thread scheduler part of JVM or OS ?

    Hi Folks,
    Just curious if the thread scheduler is a part of the JVM or OS, or either or both ?
    I tried few thread pages in JLS,but couldnot locate the exact sentence describing this.
    However some other resources have given me contradicting information.
    For example, [Reference1|http://www.deitel.com/articles/java_tutorials/20051126/JavaMultithreading_Tutorial_Part3.html] states that it is a part of the OS,whereas [Reference2|http://book.javanb.com/java-threads-3rd/jthreads3-CHP-9-SECT-1.html] states that it is a part of both.(I am not sure about the authority of these links.)
    So assuming, thread scheduling is done by JVM it is a part of the JVM only or it uses the underlying OS for support.
    Thank you for the consideration.

    This statement:
    The JVM ... operates like a mini OS and schedules its own threads regardless the underlying operating system.flatly contradicts this statement:
    In some JVMs, the java threads are actually mapped to native OS threads.They cannot both be true.
    Therefore we can say that Threads are part of JVM and OS bothRubbish. There's no 'therefore' about it. You can't draw valid logical inferences from contradictions.
    Guesswork and invalid inferences aside, the fact of the matter is that the semantics of Java threads are specified in the JLS but the execution mechanism is not. 'Any execution strategy that generates only allowed behaviors is an acceptable execution strategy.'
    I am not sure about the authority of these linksNil. They are extracts from books by third parties. Use at own risk. The JLS is where the authority is.
    Reference 2 is particularly poor, as it contradicts itself numerous times.
    For the record, Reference 2 also makes the following claims which as far as I can see are entirely baseless, for the reasons given:
    A Java virtual machine is required to implement a preemptive, priority-based schedulerThe word 'pre-emptive' does not appear in the JLS.
    The Java virtual machine never changes the priority of a thread, even if the thread has been running for a certain period of timeCan't find that anywhere either.
    the contract between the Java virtual machine and the underlying operating system is that the operating system must generally choose to run the Java thread with the highest priorityThe 'contract' is between the Java code and the JVM, not the JVM and the O/S.
    That's what we mean when we say that Java implements a priority-based schedulerJava isn't required to 'implement' a scheduler at all.
    This scheduler is implemented in a preemptive fashion, meaning that when a higher-priority thread comes along, that thread interrupts (preempts) whatever lower-priority thread is running at the time.This appears nowhere in the JLS.
    The contract with the operating system, however, is not absolute, which means that the operating system can sometimes choose to run a lower-priority thread.In other words it's not pre-emptive. Make up your mind.
    Java's requirement for a priority-based, preemptive scheduling mechanism ...Which is nowhere to be found.
    A Java thread can have one of 11 prioritiesMIN_PRIORITY is 1, MAX_PRIORITY is 10: that makes 10, not 11.
    In fact, preemption means only that a higher-priority thread runs instead of a lower-priority oneNo it doesn't. It means that when a higher-priority thread becomes ready it pre-empts the execution of any lower-priority threads that are currently executing regardless of time-slice etc. This is a feature of real-time systems that Java is not required to implement.
    Summing up, the words 'pre-emptive' does not appear in the JLS, and the word 'scheduler' only appears in reference to sleep() and yield(), without any implication that the JVM has to implement one itself.

  • Thread scheduling problem in WLS5.1

    We use a Timer Servlet to schedule some back end tasks, however we found
              that from time to time the thread scheduling often get delayed or ahead in a
              outragous magtitude.
              We run the servlet inside WLS, and right after start up, the timer works
              perfect, but after long enough time (more than one day), the timer started
              to behave weird. It could get delayed for as much as hours, and then
              suddenly fired up all delayed tasks in a very short period of time. We then
              try to run a very simple Timer doing only wake up every 10 minutes and print
              one line, that failed too. We are running WLS5.1+sp3 on
              Solaris2.6(Generic_105181-19 sun4u sparc SUNW,Ultra-5_10) with jdk1.2.1_04.
              BTW, we found that it ran well on NT, at least for three days without
              problem.
              Any feedback will be appreciated!
              Qingxiang Ke
              below is the source for the simple timer, and deploy properties for it
              inside weblogic.properties file.
              SimpleTimerServlet.java
              package com.cysive.test;
              import java.io.*;
              import java.util.*;
              import javax.servlet.*;
              import javax.servlet.http.*;
              public class SimpleTimerServlet extends HttpServlet
              class Sleepy implements Runnable
              public void run()
              while(true)
              try
              long wakeUpTime = 600 * 1000;
              Thread.currentThread().sleep(wakeUpTime);
              System.out.println(new Date().toString() + " SimpleTimer Yawn
              ............ Yawn ............");
              catch(InterruptedException ie){}
              private static boolean timerIsRunning = false;
              public void init()
              if(! timerIsRunning)
              Thread sleepy = new Thread(new Sleepy());
              sleepy.start();
              timerIsRunning = true;
              public void doGet(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException
              doPost(request, response);
              public void doPost(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException
              OutputStream os = response.getOutputStream();
              os.write("look at your std out!!!".getBytes());
              os.flush();
              os.close();
              deploy properties in weblogic.properties
              weblogic.httpd.register.simpletimer=com.cysive.test.SimpleTimerServlet
              weblogic.system.startupClass.servletSimpleTimer=weblogic.servlet.utils.Servl
              etStartup
              weblogic.system.startupArgs.servletSimpleTimer=servlet=simpletimer
              

    We use a Timer Servlet to schedule some back end tasks, however we found
              that from time to time the thread scheduling often get delayed or ahead in a
              outragous magtitude.
              We run the servlet inside WLS, and right after start up, the timer works
              perfect, but after long enough time (more than one day), the timer started
              to behave weird. It could get delayed for as much as hours, and then
              suddenly fired up all delayed tasks in a very short period of time. We then
              try to run a very simple Timer doing only wake up every 10 minutes and print
              one line, that failed too. We are running WLS5.1+sp3 on
              Solaris2.6(Generic_105181-19 sun4u sparc SUNW,Ultra-5_10) with jdk1.2.1_04.
              BTW, we found that it ran well on NT, at least for three days without
              problem.
              Any feedback will be appreciated!
              Qingxiang Ke
              below is the source for the simple timer, and deploy properties for it
              inside weblogic.properties file.
              SimpleTimerServlet.java
              package com.cysive.test;
              import java.io.*;
              import java.util.*;
              import javax.servlet.*;
              import javax.servlet.http.*;
              public class SimpleTimerServlet extends HttpServlet
              class Sleepy implements Runnable
              public void run()
              while(true)
              try
              long wakeUpTime = 600 * 1000;
              Thread.currentThread().sleep(wakeUpTime);
              System.out.println(new Date().toString() + " SimpleTimer Yawn
              ............ Yawn ............");
              catch(InterruptedException ie){}
              private static boolean timerIsRunning = false;
              public void init()
              if(! timerIsRunning)
              Thread sleepy = new Thread(new Sleepy());
              sleepy.start();
              timerIsRunning = true;
              public void doGet(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException
              doPost(request, response);
              public void doPost(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException
              OutputStream os = response.getOutputStream();
              os.write("look at your std out!!!".getBytes());
              os.flush();
              os.close();
              deploy properties in weblogic.properties
              weblogic.httpd.register.simpletimer=com.cysive.test.SimpleTimerServlet
              weblogic.system.startupClass.servletSimpleTimer=weblogic.servlet.utils.Servl
              etStartup
              weblogic.system.startupArgs.servletSimpleTimer=servlet=simpletimer
              

  • Thread scheduling

    Hi, I have some questions bout threads.
    1) When it comes to thread scheduling, Java has no say in it, since thread scheduling is solely in a domain of operating system?
    2)In preemptive environment, when thread with higher priority becomes runnable, runtime will cause lower priority thread to halt and higher priority thread to start executing. This chosen thread will run until one of the following conditions is true:
    - a higher priority thread becomes "Runnable"
    - it yields, or its run() method exits
    - on systems that support time-slicing, its time has expired
    a) Time slicing doesn't mean that every thread will get the same amount of time to run?
    b)Will higher priority threads get more time and lower less!
    c) Does Windows OS support time slicing?
    3)What kind of environment is non-preemptive environment? The kind where threads with higher priority cant preempt lower priority threads? As I understand it, in those kind of environments there is a greater chance that some threads will never run. Why?
    4)Why is under non-preemptive environment greater chance of having situation where one of the two threads with same priority will not get a chance to run?
    bye

    beginprog wrote:
    1) When it comes to thread scheduling, Java has no say in it, since thread scheduling is solely in a domain of operating system?This is not strictly true. You can control when a thread is eligible to run, but you can't force a partiular thread to run. The JVM has some control over thread scheduling, but yes, it also interacts with the OS.
    2)In preemptive environment, when thread with higher priority becomes runnable, runtime will cause lower priority thread to halt and higher priority thread to start executing. This chosen thread will run until one of the following conditions is true:
    - a higher priority thread becomes "Runnable"
    - it yields, or its run() method exits
    - on systems that support time-slicing, its time has expired I don't think Java makes any such promises about its threads' priorities. You may be describing a general model, but in terms of the JVM scheduling its threads, higher priority threads will be preferred over lower priority ones, but the exact algorithm is left up to the implementation.
    a) Time slicing doesn't mean that every thread will get the same amount of time to run? There are many ways to implement time slicing. It depends on the VM implementation and the OS.
    b)Will higher priority threads get more time and lower less!Depends on the implementation.

  • Thread scheduling mechanism in SUN's VM

    I've the problem, that n threads share a resource
    (sharedObject).
    The synchronization is done in an synchronized
    Block:
    synchronized( sharedObject )
    // do something with sharedIbject
    I would like to know in which order the thread scheduler
    of SUN Solaris VM of the JDK 1.3 or in general,
    gives the lock of the sharedObject to one of the thread, which
    are waiting for the lock of the sharedObject.
    Is there something like FIFO, so that it's safe, that all waiting
    threads will get the sharedObject in the right order,
    or do i have to implement a queueing mechanism with wait and
    notify.
    thanks

    If you're writing a Java program that uses threads, the thing to do is to follow the rules that Java provides, not the rules of a particular thread scheduler.
    There is no guarantee about which order the threads will get access to the sharedObject without writing explicit code for it.

  • Configuring Scheduled query in query manager

    Im trying to configure a scheduled query, and i have an error. If you could help me about it ill apreciate it

    Hi Theodor,
    I upgraded to 8.82 PL04 yesterday and I still can't get the report to execute. The email gets sent, but the attachment never comes with the email. This is the result from the log file:
    Looking for first schedule to be executed before/on 20120416 14:28
    Found Scheduled Report ID: 4
    Added SRA2 entry
    Handling schedule
    XML configuration sent to SAP Business One Client:
    <?xml version="1.0" encoding="UTF-16"?>
    <SR>
    <R D="20120416" T="1428" O="N">4</R>
    <L S="SAPB1SERVER" T="6" C="SBO_IEC_Production" LL="2" CU="RRehman" CP="6F5F4783DEBD49B16834D4635E93AA8B8092959226ABDE385763" LS="sapb1server:30000" LC="3"/>
    </SR>
    Starting SAP Business One Client with configuration written to its stdin
    Timeout set to 5 minutes
    *** SAP Business One Client Log ***
    Command line parsed
    StatusBar Success Message: This use of the software is subject to the End User License Agreement (EULA)
    StatusBar Success Message: No recurring transactions require posting today
    Client and server dates match, 20120416
    Starting Scheduled Report: Query
    Error #-10 encountered
    Executing XSLT transformation
    XML Input is Empty
      adding: BusinessOneb1loggerPid5552_20120416142820.Pid5552 (188 bytes security) (deflated 79%)
    *** SAP Business One Client Log ***
    SAP Business One Client return code:0
    Distributing results
    Unable to extract HTML report output to file C:\Windows\TEMP\Report.html
    Unable to extract PDF report output to file C:\Windows\TEMP\Report.pdf
    Unable to extract XML report output to file C:\Windows\TEMP\Report.xml
    SMTP Server: 172.160.2.3:25
    Sender Email: SAP Server<Server email address>
    Sending email to <my email address>
    Schedule processed
    The only other thing that I can think off, is that the printer I have linked with my report in the Print Layout Designer is a network printer, as opposed to a physical printer. Could that have something to do with it?
    Reza

  • How to schedule Query Extracts using RSCRM_BAPI

    Hi,
    Can you give me the link to the document How to schedule Query Extracts using RSCRM_BAPI  . I do not have userid password to view the same.
    Thanks for the help.

    Hi,
    this is the link for the document..
    https://websmp205.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700004400232004E
    thnks.

  • Sol 9 thread scheduling

    I posted this yesterday in the kernel forum because thread scheduling seemed more like a kernel issue than the generally admin type things usually discussed here, but I've not had any takers in kernel, so I'm trying here. Basically, while porting an application from solaris 8 to solaris 9, I seem to have run into a starvation issue with the new 1x1 thread model.
    Here is a link to the post in the kernel forum:
    http://forum.sun.com/thread.jsp?forum=10&thread=18592&tstart=0&trange=100
    Any help would be appreciated.

    I wonder why results were same. I replaced sleep(10) with an arbitrary number of busy loops, 100000
    I do see that all threads get a chance to run. I am running a 2 CPU ultrasparc each running at 1002 MHz. I do not have an understanding of your application though, but as others mentioned feel that mutexes should be used to protect critical sections (which would be small) or as a mechanism to wakeup in an async manner along with condition variables.
    pthread_starvation: press ^C to interrupt.
    Thread 6 waited 0 milliseconds.
    Thread 11 waited 5 milliseconds.
    Thread 10 waited 5 milliseconds.
    Thread 9 waited 6 milliseconds.
    Thread 8 waited 6 milliseconds.
    Thread 7 waited 7 milliseconds.
    Thread 2 waited 7 milliseconds.
    Thread 3 waited 7 milliseconds.
    Thread 4 waited 8 milliseconds.
    Thread 5 waited 8 milliseconds.
    Thread 6 waited 0 milliseconds.
    Thread 11 waited 0 milliseconds.
    Thread 10 waited 0 milliseconds.
    Thread 9 waited 0 milliseconds.
    Thread 8 waited 0 milliseconds.
    Thread 7 waited 0 milliseconds.
    Thread 2 waited 0 milliseconds.
    Thread 3 waited 0 milliseconds.
    -madhusudan

  • How to use muti-thread to query database?

    if i want to use two or more threads to query a database for data,what should i do?anybody know?

    Hi,
    I have 2 suggestions to help you do this.
    First, the Berkeley DB XML Transaction Guide uses has a multi-threaded application and several discussions about DB_THREAD.
    For more information see:
    http://www.oracle.com/technology/documentation/berkeley-db/xml/gsg_xml_txn/cxx/introduction.html#multithread-intro
    The following section should also be useful:
    http://www.oracle.com/technology/documentation/berkeley-db/xml/gsg_xml_txn/cxx/txnconcurrency.html#concurrenthandles
    If after reading about this and trying to implement you have a specific question, please post it here.
    You might also take a look in the Berkeley DB examples, TxnGuide.cpp which is a multi-threaded application.
    Ron

  • Thread Scheduling Visualizer - take a look

    Hi,
    I want to share this link with all the sun forum members.
    It is about "The Sun Java Real-Time System Thread Scheduling Visualizer"
    [http://java.sun.com/javase/technologies/realtime/reference/TSV/JavaRTS-TSV.html]
    Sun you are simply too great ;)
    thanks,
    swapnaja
    Edited by: swapnaja on Mar 16, 2009 6:43 AM
    Edited by: swapnaja on Mar 16, 2009 6:48 AM

    Hi,
    Glad it worked for you too. I'm so grateful to 'turboontheovens' for posting this solution, it was driving me crazy!
    Claire x

  • ADR Evaluation Schedule query

    I'm looking for the table that houses the evaluation schedule for my ADRs. I found the table that tells me what the last status was but not the schedule itself. I'm trying to create a report so I can have a secondary person look at the report to make sure
    we didnt miss one of our many ADRs that has to be updated monthly for our patching prcoess.

    Hi,
    Hope the following thread could give you a clue.
    http://social.technet.microsoft.com/Forums/en-US/769e8201-18cb-4110-b990-190cbaf996bb/query-to-find-collection-update-schedules?forum=configmanagergeneral
    Best Regards,
    Joyce Li
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Question about synchronize() statement and thread scheduling?

    I have threads accessing a shared LinkedList in the main thread. I made use of the Collections.synchronizedList() to avoid concurrent modifications. one of the threads is a timer thread and it has a priority of 5 and the other threads are message reception threads and i made them of a lower priority just to allow the timer thread to be executed on time. According to the javaAPI, all iterations on the synchronized list should be done using synchronized(synchronizedListRef){} and this is what i do,
    The problem is even after setting the priority of the reception threads lower than the timer thread, the reception threads are sometimes executed more than once and the timer thread is delayed. Lets assume the situation where the timer reaches the point where it has to acquire the lock (the synchronized statement) and it discovers that the lock is already taken and it cant access the list because the other thread (of a lower priority) is iterating over it. shouldnt the higherpriority thread be executed after that the reception thread (that is blocking the timer thread) finishes its execution and release the lock (even if there are other reception thread waiting)??
    does the priority play a role when a thread is blocked?

    Asady wrote:
    I have threads accessing a shared LinkedList in the main thread. I made use of the Collections.synchronizedList() to avoid concurrent modifications. Make sure you explicitly sync around all iterations. Just using Collections.sync is not enough.
    The problem is even after setting the priority of the reception threads lower than the timer thread, the reception threads are sometimes executed more than once and the timer thread is delayed.There's no guarantee as to how priority will be interpreted. The scheduler implementation is free to do pretty much anything.
    As for how to solve your problem, you might want to look at java.util.concurrent.*, e.g. PriorityQueue. If the classes there don't give you just what you need, you may be able to build on them, or at least get ideas from them. Bottom line is that if you want a specific scheduling algorithm, you'll have to implement it yourself, since Threads' priority semantics are only very loosely specified by the JLS.

  • Schedule query

    Hi,
    is it possible to schedule a query in Bex 3.x?  I mean, I'd like to perform a query each night at 9.00 pm with the value 001.2011:012_2011 for the madatory parameter 0fiscper and, the result of the query would be saved in c:\temp.
    How can I do this?
    Thanks a lot in advance.
    Regards.

    Hi,
    You can acheive this using BEx Information Broadcasting wherein you can broadcast your Query,Web Template,Reports and workbooks(this is through Precalc Server).You Broadcast the report through Broadcast EMail option and you can schedule it to send automatically to the users.
    Their are some steps which you can follow
    Step1
    Create and save a workbook
    Step2
    Open the created workbook in the in the Bex Analyzer
    Step3
    Go to Bex Analysis Toolbox and click on Tools button
    Step4
    Login to the IB page to create settings
    Step5
    Create a new setting by giving the appropriate e-mail id
    Step6
    In the Texts tab give the subject and Text
    Step5
    Provide the variable and server details
    Step6
    Click on schedule and give appropriate date and time.
    Thanks,

  • Daily Scheduling Query

    Hi
    I have a daily job, that runs several Warehouse Builder processes, scheduled to run at 2am each day. Normally this should complete by 9am, however if there are any performance issues, there is risk that the job may still be running at 2am the following day.
    If this situation occurs, would the first job which started on a Monday 2am still carry on running until complete and then start the Tuesday job (even if later than Tuesday 2am). Or would the Monday job be killed on Tuesday 2am, and then the Tuesday 2am job start?
    I realise I could create a window, however since the OWB processes will carry on running in the background, I do want all jobs to complete before moving onto the following day.
    Can anyone help with this please?
    Thanks
    GB

    Hello Mark...
    Amer is right. You can create a broadcast setting to daily sends your
    query as MHTML format.
    You can send to your e-mail but there is a possibility to save on KM and CM repository.
    There is a little explanation on the link below:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/5c6b686a-0901-0010-8aab-c4d0e5a093a7?quicklink=index&overridelayout=true
    To create a broadcast setting, open the query via Query Designer.
    Click "Query" -> "Publish" -> "BEx Broadcaster"
    While you are creating the broadcast, there is a "Output Format" option.
    There is MHTML.
    I hope you find this information useful.
    Thanks
    Edward

  • To schedule query reports

    Dear Experts
    Please let me know how can to cinfigure scheduler on query reports in 8.81?
    Thanks in Advance
    Regards
    Kanishka Tyagi

    Hi Kanishka ,
    You can schedule the query by using Alert Management
    You have to set a alert based upon that query
    and have to set the frequency (may be Hours / Day / week / Months)
    on a specified Time .
    Hope it Helps
    Thanks
    Ashish

Maybe you are looking for

  • Read Only Columns

    Hi, We have designed a update METADATE type custom integrator to download, update and re-upload data to Oracle Apps. As a part of the integrator we are displaying few extra columns for the end users viewing purpose. The client want us to make such vi

  • When I plug in my sony hdd handycam to my mac it comes up on the desktop but will not appear in iMovies. Therefore I cannot import the video I want.

    It is very frustrating. It will not come up as an option in the 'import video' window. I can only import video that is recorded from the 'in built' camera on my computer. Any one know how I can overcome this?? I would really appreciate any help.

  • How to create a matrix report with xml

    Hi, I have a problem with a maxtrix report ,I got the output from the application but I don't know how to create it at the bi puplisher in order to get the righte template. So if any one know the answer or have a useful decomentation send it me . Ema

  • Date format in IDT

    Hi, I have an universe based on Teradata. I created a filter in IDT and it's like this : @Select(Sales\Calendar Day) =  @Prompt('Date:','D',,Mono,) When I use this filter and execute a test query in IDT, the date format is shown different in these 2:

  • How to get each account balance in sapscript when using F.01

    Dear Friends, I had developed a sapscrit form for P/L statement ( TCODE F.01) printing Now I received a new requirement. I need to get the balance values for each account and check the credit/debit indicator in sapscript. Do anyone know how to do it?