Specifying what thread to execute

Hi There,
I am learning about the new concurrent package in 1.5 and I think its great.
There are times though where I would like to specify the thread that is to be used to execute a particular task. For example, it would be great if I could do the following:
ExecutorService threadExecutor = Executors.newFixedThreadPool(4);
threadExecutor.execute(task1, 0); // always use "Thread0" to execute this
threadExecutor.execute(task2, 1); // always use "Thread1" to execute this
threadExecutor.execute(task3, 2); // always use "Thread2" to execute this
threadExecutor.execute(task4, 3); // always use "Thread3" to execute thisThe example above is simplistic to illustrate the wished for API call. I do need this functionality over the course of a run of the application I am currently working on. Do I need to forget about the high level API and go low level on this one?
thanks a lot,
- Paul.

The ThreadExecutor uses a single queue so there's no way to distiguish threads in the pool. The thread you wanted could be busy.
You could simply use a separate Executor with one thread for each.

Similar Messages

  • Lsmw error 'Specify Files first' while executing option 'Read Data'.

    Hi All,
    while trying to create mass users through LSMW, i am gettign the error 'Specify Files first' while executing option 'Read Data'.
    I have specified file (.txt), manually created (with'1 tab space' between each term). i have used option 'On the PC(Frontend)'. No error while saving.
    Next- i have executed 'Assign Files', where the file appeared automatically.
    Next- Here, when i try to execute 'Read Data', i get the error 'Specify Files first'.
    Can anyone help in resolving this error.

    Hello Plaban,
    What is your purpose? Are you tring to upload the data with more file variant?                                                                               
    There are two possibilities to make file names more variable:                                                                               
    1.If you choose system dependent file names by setting the according flag (in the first step 'Maintain object attributes'), you can define file names for each system in step 'Specify files' by assigning the files to a specific system ID (with a double-click on the specified file).                                                                               
    2.You can use wildcards in the file names where you can assign several values.                                                               
    I hope this helps you.
    Regards,
    Blanca

  • 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

  • What is "with execute as caller" in SP?

    What is "with execute as caller" in SP? 
    What is the purpose of this command?
    Thanks in advance.

    Here is the explanation 
    http://msdn.microsoft.com/en-us/library/ms188354.aspx
    CALLER
    Specifies the statements inside the module are executed in the context of the caller of the module. The user executing the module must have appropriate permissions not only on the module itself, but also on any database objects that are referenced by the module.
    CALLER is the default for all modules except queues, and is the same as SQL Server 2005 behavior.
    CALLER cannot be specified in a CREATE QUEUE or ALTER QUEUE statement.
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Hi, i have tryed to install os x leopard, (its a old imac) , disk utility is greyed out , my install dvd cant find any hdd to install on , my only way to format and configure is through terminal but dont know what commands to execute

    hi, i have tryed to install os x leopard, (its a old imac) , disk utility is greyed out , my install dvd cant find any hdd to install on , my only way to format and configure is through terminal but dont know what commands to execute...
    i tryed diffrent commands such as diskutil eraseDisk JHFS+ Disk1
    diskutil list , wont show up my harddrive , i now its functionally cause it shows up in disk utility with name and i can get info about it , but everything is greyed out can only switch between "erase , partition , recover , Raid ,....
    when i click the apple in the top left corner the whole menu is greyed out... what to do ?  help me please
    Sincerly AppleNoob92
    p.s i have no experience in apple imac's at all never used before, but im kinda windows nerd so computers i understand but this imac make my insane, cant seem to find any solutions anywhere on the WWW....

    Your HD may be crashed, so you probably should use the oringinal install discs to run Apple Hardware Test in extended mode. If error codes appear this confirms a hardware failure. In addition you cannnot repair the HD using Disk Utility from the startup disk, you have to use the origninal Install discs that shipped with the computer or the most up-to-date version of OS X on a disc that you have.

  • How do you specify what format you want the song to download in?

    How do you specify what format you want the song to download in?

    In preferences set up your import settings, then right click on the tracks you need in a different format and use Create < Format> Version. New copies will be created in the target format.
    tt2

  • What business event executes when a Party is updated

    Hi,
    What business event executes when a Party is updated ?
    I tried with
    oracle.apps.ar.hz.Organization.update
    oracle.apps.ar.hz.CustomerProfile.update
    None of these seems triggering when Party information is updated example: Customer Profile, Customer Name itself.
    Thanks
    Saikrishna

    Please see if (Customers Workbench: No Business Event Firing When Activating/Inactivating An Account Contact (Doc ID 1553927.1)) helps.
    Thanks,
    Hussein

  • To differentiate in the user-exits what transaction has executed first

    Hi,
    I have a problem,
    For transactions Iw32 y iw34 EXIT_SAPLCOIH_006 user-exit  are called up  when a maintenance order is updated
    from any of two transactions.
    I want to differentiate in the user-exits what transaction has executed first (origin) because sy-tcode in both cases contains  iw32 ' because IW38 transaction calls UP always to the transaction iw32 for update of a maintenance order.
    thank´s
    Regards.

    If that is the case, and the IW32 is begin called from IW38 via some batch input mechanism, then maybe this code will work.  You can wrap your code in this IF statement.  Here we are saying that we only want to do this when the tcode is IW32 and it is not being called in batch input(call transaction) or called by another program.
    if sy-tcode = 'IW32'
      and sy-binpt = space
      and sy-calld = space.
    endif.
    Regard,
    Rich Heilman

  • What is an executable class

    What is an executable class in java. Can someone explain with an example??

    I'd guess a class with a public static void main( String[] ) method.
    i.e.
    public class Test {
        public static void main( String argv[] ) {
              System.out.println( "BOO!" );
    }javac Test.java
    it can the be executed with the java command:
    java Test
    Resources for Beginners
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java. This one has been getting a lot of very positive comments lately.

  • TS4062 everytime i try to sync my iphone 5 on itunes it states " The iphone5 cannot be synced. A duplicate file was specified. what do i do

    everytime i try to sync on itunes the message "The iphone5 cannot be synced. A duplicate file name was specified" what do i do to rectify this?

    Hi giggle chops,
    Welcome to the Support Communities!
    The article below explains why you may get this specific error message.  Follow the instructions below to disable any third-party plug-ins by opening iTunes in Safe Mode:
    iTunes: Troubleshooting issues with third-party iTunes plug-ins
    http://support.apple.com/kb/ts3430
    Symptoms
    Add-ons, such as plug-ins and scripts, not manufactured by Apple (third-party) add features to iTunes or modify its appearance and behavior. Using these can interfere with how you use iTunes. For example, if you upgrade to a newer version of iTunes, your add-ons may not be compatible.
    You see this alert while syncing: "... cannot be synced. A duplicate file name was specified."I
    I hope this information helps ....
    - Judy

  • How to specify what is displayed for dimension members in the Crosstab

    Is there a way to programatically specify what the Crosstab displays for each dimension member. I want to be able to switch between the short label and long label of the member data. Thanks

    Hi,
    At the moment there is no facility to do this. However, the next version of BI Beans which will be shown at Oracle World in September should have this capability.
    Hope this helps
    BI Beans PM Team
    Oracle

  • When printing not all specified pages print or when specifying what pages to print all pages print

    I am using the deskjet 3050A printer  along with windows 7. When printing if I specify specific pages to print for example page 1,3,5 it will only print page 1 and 3. Sometimes when specifying what pages to print it will continue to print all pages. I'm not sure if it is an error with the wireless communincation.

    HI littlek5,
    What program or application are you printing from ?
    Does it do the same thing if you print from another application ?
    If I helped you at all it would be great if you clicked the blue kudos star!
    If I solved your post please mark it as solved to help others.
    I'm a printer tech with HP.

  • HT4489 Is there a way to limit (specify) what is shared when you share a contact?

    I noticed when I share a contact that most information in the contact is shared.  This is not what I want.  I would only like to share the basic information like telephone numbers and addresses.  I do not want to share my notes and additional information that I have accumulated.  Is there a way to limit or specify exactly what you want to share?

    This isn't a way to limit what is shared, except to create a new contact to share that excludes this information.

  • Using DRS to specify Java version when executing JNLP file.

    We have an application that executes from a JNLP file that we are told is version sensitive.  We have a rule set created for a number of apps that work just fine to meet this goal.  However, when creating a rule to execute this JNLP application we are having issues getting it to work.  To simplify the process we created a certificate hash rule for this application and when reviewing console\trace we can see it correctly identifying and executing under the Java 6U29 environment.  The issue is that even though 6u29 is being invoked it does not work (merely displays a "application error" message).  However, if I instead launch the JNLP file using the Javaws.exe in the 1.6.0_29 folder the app loads fine.  When comparing behavior with the rule set environment and a 6u29 only environment I saw some peculiar entries. 
    basic:   jvmParams: [JVMParameters: isSecure: false, args: "-Xmx256m" "-Xms32m" "-DEAS_HOME=http://appserver:10080/easconsole/" "-DEPM_ORACLE_INSTANCE=http://appserver:10080/easconsole/" "-DUSE_FOXTROT_BY_DEFAULT=NO" "-DDEFAULT_COMMAND_MANAGER=com.essbase.eas.framework.client.defs.command.UICommandManager" "-Deas_country=US" "-Deas_language=EN" "-DEAS_CONSOLE_LOG=LOG_NULL" "-Djava.util.logging.config.class=oracle.core.ojdl.logging.LoggingConfiguration" "-DmaxFileSize=1000000" "-DmaxLogSize=5000000" "-Dformat=ODL-Text" "-DEAS_LOG_FORMAT=ODL-Text" "-Dsun.awt.keepWorkingSetOnMinimize=true" "-Dswing.defaultlaf=oracle.bali.ewt.olaf2.OracleLookAndFeel" "-Dswing.metalTheme=OracleBlueTheme"]
    basic: cmd 0 : C:\Program Files\Java\jre1.6.0_29\bin\javaw.exe
    basic: cmd 1 : -Dsun.awt.keepWorkingSetOnMinimize=true
    basic: cmd 2 : -Dswing.metalTheme=OracleBlueTheme
    basic: cmd 3 : -Xmx256m
    basic: cmd 4 : -Xms32m
    Xbootclasspath/a:C:\Program Files\Java\jre1.8.0_25\lib\javaws.jar;C:\Program Files\Java\jre1.8.0_25\lib\deploy.jar;C:\Program Files\Java\jre1.8.0_25\lib\plugin.jar
    basic: cmd 6 : -classpath
    basic: cmd 7 : C:\Program Files\Java\jre1.8.0_25\lib\deploy.jar
    basic: cmd 8 : -Djnlpx.vmargs=LURzdW4uYXd0LmtlZXBXb3JraW5nU2V0T25NaW5pbWl6ZT10cnVlAC1Ec3dpbmcubWV0YWxUaGVtZT1PcmFjbGVCbHVlVGhlbWUALVhteDI1Nm0ALVhtczMybQA=
    basic: cmd 9 : -Djnlpx.jvm=C:\Program Files\Java\jre1.6.0_29\bin\javaw.exe
    basic: cmd 10 : -Djnlpx.splashport=50425
    basic: cmd 11 : -Djnlpx.home=C:\Program Files\Java\jre1.8.0_25\bin
    basic: cmd 12 : -Djnlpx.remove=false
    basic: cmd 13 : -Djnlpx.offline=false
    basic: cmd 14 : -Djnlpx.relaunch=true
    basic: cmd 15 : -Djnlpx.session.data=C:\Users\Username\AppData\Local\Temp\session7225377494424974596
    basic: cmd 16 : -Djnlpx.heapsize=33554432,268435456
    basic: cmd 17 : -Djava.security.policy=file:C:\Program Files\Java\jre1.8.0_25\lib\security\javaws.policy
    basic: cmd 18 : -DtrustProxy=true
    basic: cmd 19 : -Xverify:remote
    basic: cmd 20 : -Dsun.awt.warmup=true
    basic: cmd 21 : -Djava.security.manager
    basic: cmd 22 : com.sun.javaws.Main
    basic: cmd 23 : C:\Users\Username\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\2\56c68c82-305f8577
    network: Created version ID: 1.7
    basic: Exiting
    So it appears that the 6u29 version of Javaws.exe is getting called however some of the configured paths are being set to the 8u25 path.  Not sure if its a cause but does seem to be relevant since on the exact same system if I run the JNLP specifically with the 6u29 exe it works as expected.  Any assistance would be appreciated. 

    sunjavaboy wrote:
    ..how do I specify a specific range of JREs in the jnlp file so that JWS picks up a JRE from that range only? So if 1.5.0_07, 1.5.0_17 and JRE 6 are installed, it should run the app on 1.5.0_17.From the JNLP Specification
    *4.6 Java Runtime Environment*
    Several JREs can be specified, which indicates a prioritized list of the supported JREs, with the most preferred version first. For example,
        <java version="1.3" initial-heap-size="64m"/>
        <java version="1.2">
          <resources> ... </resources>
        </java>So your app. would need more along the lines of..
        <java version="1.5.0_07 1.5.0_08 1.5.0_09 1.5.0_10 1.5.0_11 1.5.0_12 1.5.0_07 1.5.0_13 1.5.0_14 1.5.0_15 1.5.0_16 1.5.0_17 " />
        <java version="1.6+" />Actually you'd need the list of 1.5 versions reversed. Well, you get the idea hopefully. For more on versioning, see my [JWS versioning page|http://pscode.org/jws/version.html].

  • TIme taken by Child threads to execute

    Hi
    I have a small query related to multithreading. I have a main thread launching a few Child threads. Now I want to check how much time all the 10000 child threads are taking to execute. I cannot write a System.currentTimeMillis(); before a main thread exits because I want the Child threads to keep executing even after the Main thread exits because I do not know how much time the child threads will take. I have made the child threads as non-deamon
    class ChildThread implements Runnable {
         Thread t;
         int i;
         ChildThread(int i) {
              t = new Thread(this, "SMS Thread");
              this.i = i;
              t.setDaemon(false);
              t.start();
         public void run() {
              try {
                   System.out.println(i);
              } catch (Exception smsex) {
                   System.out.println("Exception occured while sending message :"
                             + smsex.getMessage());
                   smsex.printStackTrace();
    public class MainThread {
         public static void main(String args[]) {
              long start = System.currentTimeMillis();
              ChildThread thread = null;
              try {
                   for (int i = 10000; i > 0; i--) {
                        thread = new ChildThread(i); // create a new thread
              } catch (Exception e) {
                   System.out.println("Main thread interrupted.");
              long end = System.currentTimeMillis();
              System.out.println("Main thread exiting. Took " + (end - start)
                        + " ms.");
    }

    This is a sample i have assumed.. dont have the complete code.
    I will just explain this
    Create an executor service object in a class called ThreadDispatcher.
    And create your chileThread as given below
    class ChildThread implements Runnable {
         ChildThread() {                    
         public void run() {
              try {
                   System.out.println(i);
              } catch (Exception smsex) {
                   System.out.println("Exception occured while sending message :"
                             + smsex.getMessage());
                   smsex.printStackTrace();
    }And the ThreadDispatcher class as below -This is just to beautify the code :)
    public class ThreadUtil {
    private static ExecutorService exec = Executors.newFixedThreadPool(some_value);
    public static List<Future> executionResults = new ArrayList<Future>();
    }And finaly come to the main Thread class
    public class MainThread {
         public static void main(String args[]) {
              ChildThread thread = null;
              try {
                             long start = System.currentTimeMillis();
                   for (int i = 10000; i > 0; i--) {
                        thread = new ChildThread(i); // create a new thread
                                    ThreadDispatcher.executionResults.add(ThreadDispatcher.exec.submit(thread));
              } catch (Exception e) {
                   System.out.println("Main thread interrupted.");
                    //Here place the while loop to check each thread status
                     while (ThreadDispatcher.executionResults.size() > 0) {
                   try {
                        Future task = ThreadDispatcher.executionResults.get(0);
                        task.get();//Wait until the thread finishes execution
                                    ThreadDispatcher.executionResults.remove(task);
                   } catch (InterruptedException e) {
                        e.printStackTrace();
                   } catch (ExecutionException e) {
                        e.printStackTrace();
              long end = System.currentTimeMillis(); //This time will probably be the end time.
              System.out.println("Main thread exiting. Took " + (end - start)
                        + " ms.");
    }Hope this will be helpful...

Maybe you are looking for

  • How to highlight/indicate particular tree Node in Tree UI element

    Hi All Can anybody let us know how to highlight/indicate specific node in a tree struture. currently i am able to display the tree struture with all the nodes & elements but it is always tasking firstnode as highlighted one or indicated one. if i wan

  • APP-Problem in creating payment order

    Hi Gurus, I have created payment proposal for vendors in F110. Now, when I am checking the payment proposal in FBZ0 all the vendor line items are marked in RED in the Type Column which i guess should be green. Please let me know if it is ok or what c

  • Printing 4x6 Photos in Adobe Photoshop Album Starter 3.0

    Some time ago, I thought I downloaded a fix to this program to allow three 4x6 photographs to be printed on one page. I can't find this subject again. The problem is that although the Print Preview shows three 4x6 prints on a page, it actually prints

  • Captureing from a dv camera....

    i have been using the capture feature in fcp to log each in and out i want to be a clip and then batch capture but i want to be able to just press one button and have it capture every clip i shot from where ever i have it start from to the end or whe

  • Application Language Problem

    Hello, I am writing From Turkey. I have an iphone 5s and i believe i am the one of first iphone 5s buyer in Turkey. I had a problem and i called apple and nobody solved my problem. I tunes help desk or whatever thay said that problem is not their pro