Concurrency in Java Thread.

Hello Friends,
I need to create two threads and these threads should be run parallelly.
I explain in detail.
I have function1(). From that i will call func2(). Inside func2() i will start a Thread also call func3().
Now i need to perform these processes from two different Threads with different Parameters.
function1() {
int i;
func2();
func2() {
Thread t = new Thread();
t.start();
func3();
func3() {
I need to call function1() from a thread. At the same time i will call the same function1() with different parameters.
Anybody knows the idea, please give your ideas please.
Thanks in advance
Rgds
tskarthikeyan

TSKarthikeyan wrote:
Hello Friend,
I explain below.
Func1() {
Func2();
Func2() {
Thread t3 = new Thread();
t3.start();
This is the functionality. Now i have to perform these steps from two different threads in parallel with different parameters.
If i call these steps from two different Threads, then how it works. How can i implement that functionality. So that , Two Different Threads call the same function ie,Func1(). How this function works with two Different Threads.You're still not explaining very well, but if you want two different threads to call func1 with two different parameters, it'd be something like this.
public class MyRunnable implements Runnable {
  private final SomeType param;
  public MyRunnable(SomeType param) {
    this.param = param;
  public void run() {
    somethingElse.func1(param);
SomeType param1 = new SomeType();
SomeType param2 = new SomeType();
Runnable r1 = new MyRunnable(param1);
Runnable r2 = new MyRunnable(param2);
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
t1.start();
t2.start();

Similar Messages

  • Java thread not working in windows 7

    I have a Java app that runs just fine on Windows XP. However, on Windows 7 there is a problem related to a job being done via a Java thread.
    Background: The app spawns a separate job via a Java thread and continues on while the spawned job executes. In other words, 2 things happen at once.
    Problem: On Windows 7, when the app spawns the job, Windows sits and waits for the spawned job to complete before it continues on. In other words, 2 things DO NOT happen at once.
    It's as if Java threading does not work in Windows 7. Any input would be greatly appreciated. Thanks.

    l_sleven wrote:
    Thanks for the input, guys. From now on I'll be sure to include a SSCCE.
    I'm beginning to believe this is actually my ignorance of threading in SWT, and XP was more forgiving than 7.
    I would include a SSCCE, but of the 4 different ways I tried to get this to work I wouldn't know which to include since all failed to fix the problem.
    If you want to identify a link to a web page identifying 'best practices' for SWT threading, that would be great. Be aware though that there's a good chance I've already googled the page.
    A programmer smarter than me once said, "The road to best practices is a bumpy ride".[Concurrency in Swing|http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html]

  • I want to execute other java thread in the JNI.

    Hi!
    I would like to execute other java native thread concurrently in the Java Native Interface.
    When a Java thread called a native thread to use java native interface, Java thread is blocking for processing native thread.
    So, other java threads don't execute because they are blocking.
    Why do these problems occur at JVM(personal basis profile:CVM)?
    I hope you explain this reason in detail.
    Regard.
    Message was edited by:
    peeppeep

    Cross post
    http://forum.java.sun.com/thread.jspa?threadID=786857&messageID=4471999#4471999

  • Java thread pauses

    Hi,
    I am tuning a Java application, which takes a task from a queue and executes it continuously. My Queue and the thread which adds a task to it is in native C code and I am getting the data from it using JNI in the Java main thread. I am measuring the processing time of that task and finding the min/max/avg. I am observing that though the overall processing time is as expected, there are some big outliers. The Java thread pauses for some time and which causes these outliers.
    I want to tune my application so that there will not be any pauses in the executing java thread. I tried out some GC options (parallel as well as concurrent low pause collector) but didn't get rid of these. Could someone suggest right parameters or a way to avoid these pauses?
    Note: If I run exactly similar task completely through C code I don't see these outliers, so this is most probably something in Java rather than my application
    Thanks.

    How big are your "big outliers"? What does running with -XX:+PrintGCTimeStamps -XX:+PrintGCDetails show? Do the start times shown there correspond to the outliers you see? Do the pauses you see there correspond to the outliers?
    Post a log here from trying the concurrent (low-pause) collector, along with your command line parameters and the characteristics of your machine (number of processors, amount of physical memory, which version of the JVM you are using, etc.), and I'll try to help.
    On java.sun.com you can search for "Java memory tuning" and get several pointers to documents to help you tune for your application.

  • A blocking problem of java thread.

    Hi!
    I would like to execute native thread concurrently in the Java Native Interface.
    When a Java thread called a native thread to use java native interface, Java thread is blocking for processing native thread.
    So, other java threads don't execute because they are blocking.
    Why do these problems occur at JVM(personal basis profile:CVM)?
    Regard.
    Message was edited by:
    peeppeep

    you need to explaing the problem more clearly, maybe post the code?

  • Java Threads not being released after loggin off

    Hello everyone,
    We are seeing a weird problem in our PI 7.0 box.
    Once I logout from the XI box (both ABAP and Java stck) my basis tem still sees Java threads aginst my id still open. Our system does not seem to be realeasing Java threads.
    Is this a know problem? What are the remidition steps.

    Hi,
    Are there existing HTTP sessions only?
    The following might be helpful.
    http://help.sap.com/saphelp_nw73/helpdata/en/c7/5ee440ba994fa3b187ff2f050cfe7c/content.htm
    http://wiki.sdn.sap.com/wiki/display/ERPHCM/Sessionnotendingafterlogoff
    Regards,
    Varun

  • Java threads monitoring

    I am using Java threads in my Java program, running on Windows Professional 2000. I am monitoring the threads using Windows Performance Monitor (WPM). However, even running a small Java program which creates only 2 threads, results in many (at least 10) instances of Java threads being reported by the WPM. Problem is, in WPM, there is no way to determine which threads in the WPM are the threads that I programmatically created. Any ideas on how to determine this?
    Thanks.
    Rhodie

    Hi Dmirty ,
    To handle large asynchronous message   in queues you can use  message packaging where multiple message are processed in one package . to make it applicable you have to perform these simple steps
    1. go to SXMB_ADM add one RUNTIME parameter PACKAGING and value 1
    2 GO TO transaction SXMS_BCONF set delay time 0 message count 100 messages and package size 1000 KB
    with these setting your improvement will increase .secondly also put  IN SXMB_ADM monitor category parameter QRFC_RESTART_ALLOWED TO 1
    this will automatically start your queue . Only thing you have to take care if you enable packaging them don't keep too many parallel queue i.e EO_INBOUND_PARALLEL and EO_OUTBOUND_PARALLEL should be less than 20
    Regards,
    Saurabh

  • Java Threads Problem

    Hi, I am trying to write a simple java threads program where in one thread reads a file and another thread writes the data into a second file....
    Here is my code, although i think i am correct, my program still runs in a sequential fashion help help help!!!
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    class MyThread extends Thread{
    private int a;
    private int c;
    FileInputStream in;
    FileOutputStream out;
    public MyThread(int a){
    this.a = a;
    public void run(){
    if(this.a==5)
         try {
         in = new FileInputStream("Britney.txt");
    } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    try {
         while((c=in.read())!=-1)
              a = (char) c;
              System.out.println(a);
    catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    if(this.a==10)
         try {
              out = new FileOutputStream("romi.txt");
         } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         for(int i = 0;i<50;i++)
              try {
                   System.out.println(c);
                   out.write(c);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    class MainMyThread{
    public static void main(String args[]){
    MyThread thr1, thr2;
    thr1 = new MyThread(5);
    thr2 = new MyThread(10);
    thr1.start();
    thr2.start();
    }

    Encephalopathic wrote:
    malcolmmc wrote:
    ... Chances of getting any kind of reply except "me too" can be pretty remote. ....there's actually a better chance of getting a reply on a general forum like this one, ....Can't you just post in both the narrow and the general forum, but include links one to the other in each thread? Or is that against the forum rules/etiquette? Most people here are ok with a crosspost IF those links are included.
    I would also ask that the OP designate one of those threads as the real discussion thread and just direct folks there from the other threads, so that we have one coherent discussion. If he does that, there's no problem with trying to reach out to as broad an audience as possible.
    I would figure that if the poster were upfront about what they are doing, folks wouldn't mind, but I could be wrong.I think that's generally the case. As long as the discussion is confined to one thread (and pointed there from the crossposts) or at the very least all the participants can see all the discussions, I think most people don't have a problem with it. It's when we waste our time answering when he's already got the answer elsewhere that's annoying.

  • Java thread with high CPU usage

    Hi,
    Running prstat -L -p pid on Solaris produces a list of lwp threads running in that process that are consuming the most CPU. Out of about 7 threads that were associated with kernel threads in pstack output, only 5 of them were mapped to a JVM thread dump. How is it possible to have a Java thread consuming CPU that doesn't show up in a thread dump?
    Thanks,
    J.S.

    And, any idea what this thread is doing?
    Here's pstack output for this missing thread 12:
    ----------------- lwp# 18 / thread# 12 --------------------
    fe0e48b4 __1cHCompileSflatten_alias_type6kMpknHTypePtr__3_ (b6001780, 100360, fe4c8000, b6001780, 100360, 0) + 4d8
    fe0f42ac __1cHCompilePget_alias_index6kMpknHTypePtr__I_ (b6001780, 100360, b6001264, 7e2bb8, 41f4, 7e2bb8) + 8
    fe11131c __1cJStoreNodeFIdeal6MpnIPhaseGVN_pnLPhaseDefUse__pnENode__ (0, 7dd5b4, 5035ec, 7e2bb8, b6001144, b6001264) + 128
    fe0c1224 __1cMPhaseIterGVNNtransform_old6MpnENode__2_ (0, b6001144, 7e2bb8, b6001264, 7e2bb8, b600116c) + 47c
    fe17349c __1cMPhaseIterGVNIoptimize6M_v_ (24, 0, a37700, b6001110, b6001100, 3442f0) + b4
    fe1943b0 __1cOPhaseIdealLoop2t6MrnMPhaseIterGVN_pk0_v_ (b6000ee8, a3772c, 1, 4ff37c, 2000, 269568) + 7cc
    fe1cc89c __1cHCompileIOptimize6M_v_ (b6001780, b60015b8, b6001780, b60015dc, 0, b60013dc) + a0
    fe1cb69c __1cHCompile2t6MpnFciEnv_pnHciScope_pnIciMethod_ill_v_ (91f504, b6001800, db8a24, fe5296b4, b60018a0, b60018b0) + 7bc
    fe1c73f8 __1cKC2CompilerOcompile_method6MpnFciEnv_pnHciScope_pnIciMethod_il_v_ (27b18, b6001af8, db8a24, db8938, ffffffff, 1) + 70
    fe1c79fc __1cNCompileBrokerZinvoke_compiler_on_method6FpnLCompileTask__v_ (db8938, db8a24, fe4eacec, 0, 0, 8d9) + 40c
    fe280964 __1cNCompileBrokerUcompiler_thread_loop6F_v_ (28758, 13a570, fe4c8000, b6001d10, fe4c8000, ffffffff) + 168
    fe216200 __1cKJavaThreadDrun6M_v_ (b5e02000, fe4d3e34, fe4c8000, 1ffd70, 13a570, 1ffd70) + 3d8
    fe213ec8 _start   (fe4c8000, ff325d10, 0, 5, 1, fe401000) + 20
    ff36b734 threadstart (13a570, 0, 0, 0, 0, 0) + 40

  • How to terminate a java thread from c++ code?

    Hi,
    I made a screensaver which loads a jvm, forks a thread running a java class, wait until user's action(i.e. mouse move/click keyboard input), then terminate the java thread.
    However, I met a problem, How to terminate a running java thread from c++ code?
    Here is my code, but it does not work: (even after the terminate is called, jvm throws an error)
    JNIEnv* env;
    JavaVM* jvm;
    HANDLE hThread; //handle for the startThread
    unsigned __stdcall startThread(void *arg)
         jclass cls;
         jmethodID mainId;
         jint          res;
         int threadNum = (int)arg;
         res = jvm->AttachCurrentThread((void**)&env, NULL);
    cls = env->FindClass( MAIN_CLASS);
         mainId = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
         // setup the parameters to pass to main()
         jstring str;
         jobjectArray args;
         int i=0;
         args = env->NewObjectArray(1, env->FindClass("java/lang/String"), 0); //only one input parameters
         str = env->NewStringUTF("localhost");
         env->SetObjectArrayElement(args, 0, str);
         env->CallStaticVoidMethod(cls, mainId, args); // call main()      
         if (env->ExceptionOccurred()) {
                   env->ExceptionDescribe();
         return TRUE;
    Here is the main method:
    First create the jvm and load the thread. then tries to terminate the thread, but failed here
    switch (msg)
    { case WM_CREATE:
              JavaVMOption options[NUMBEROFOPTIONS];
              JavaVMInitArgs vmargs;     
              jint rc;
              vmargs.version = JNI_VERSION_1_4; /* version 1.4 */
              vmargs.options = options;
              vmargs.nOptions = NUMBEROFOPTIONS;
              vmargs.ignoreUnrecognized = JNI_FALSE;          
              rc=JNI_CreateJavaVM( &jvm, (void **)&env, &vmargs ); /* create JVM */
              /* We pass the thread number as the argument to the invoked thread */
              unsigned int threadId = -1;
              // to initialize a thread-safe C runtime library
              hThread = (HANDLE)_beginthreadex(NULL, 0, &startThread, NULL, 0, &threadId );
    } break;
    case (WM_DESTROY):
              CloseHandle( hThread );
              jvm->DestroyJavaVM(); /* kill JVM */
              Debug("Destroy Java Virtual Machine\n");
    }break;
    Note, after the thread "startThread" runs, it has an infinite loop and will not terminate, until the user clicks to terminate.(I didn't call jvm->DetachCurrentThread();_endthreadex(0); in the "startThread" because the java thread will not terminate by itself)
    Thus, the only way to terminate the thread is to call closehandle(hthread) in the main thread, which may cause jvm to throw an error.
    Do you know how to terminate a java thread safely???
    Thanks a lot

    Assuming that your java thread is in a loop of some kind. Such as
    int i=1; /* I tried using a boolean, I just could not get my C++ env, to change this value. So i decided to use an int */
    run {
    while(i)
    isdfjsdfj
    void seti()
    i=0
    So, B/4, i call destroyVM in my C++ code, i call this seti(). so the loop terminates, therefore my thread finishes executing and ends.
    Hope this helps
    tola.

  • Best option for Asynchronous method invocation? JMS or Pure Java Thread

    Hi,
    We've a swing based Client application which is supposed to run with a server in J2EE environment. Some process like Search etc are very time consuming. So we are going for asynchronous process.
    Now the question is to find a best option for this. Two possible candidates are
    1. JMS
    2. Java Thread.
    Can anybody suggest me which one is the best option in this context?

    Actually my thought was the issues with code maintainability.Maintainability is different issue, it is much related to OOAD and design pattern you might want to choose to avoid coupling (thus high reusability and maintainability - eg: for future enhancement, etc)..
    public interface SearchService {
         public static class DefaultFactory {
                 public SearchService getInstance() {
                          return HttpSearchService.getInstance();
         public void search (String[] keywords, Observer obs);
    public class HttpSearchService implements SearchService {
         public static HttpSearchService getInstance() {
                ... bla bla bla singleton ...
         public void search(final String [] keywords, final Observer obs) {
                     (new Thread() {
                              public void run() {
                                    .. do http request ...
                                    List result =  ... parse http response ...
                                    obs.update(list);
                     }).start();
    SearchService ss = SearchService.DefaultFactory.getInstance();
    ss.search( new String[] { "get", "me", "my" , "dukes" }, myTableModel );
    ...You can, in future, replace the default factory HttpSearchService with something faster, more appropriate SearchService, without changing many codes.
    rgds,
    Alex

  • Multiple java threads in a JVM created by the invocation interface

    Hi,
    I have a certain application APP that calls functions of a C library. One of these functions creates a JVM through the invocation interface. In the JVM I create some other threads and a Swing GUI. From the java "main" thread as well as the other threads (including the Swing event dispatcher thread) I need to call dll functions through native java methods. The latter indirectly (through another dll) invoke functions of an API of application APP.
    I have problems when making calls from the java threads to the java native library. In some cases everything works well i.e., I'm able to make calls to the java native library from both the "main" java thread and the other threads. In other cases a crash occurs when attempting to access the native library from any threads but the "main" thread.
    Can anyone help me on this? Is there any requirement that only the main java thread makes callbacks to C code?
    Thanks.

    > why later sets of java application is taking longer?
    Probably because of CPU usage.  But could be memory.
    >Can I do something here so that later sets of apps also completes in 3 mins
    You tune the task, the complete task, to the box.  That means you must understand in detail what is taking time and then architect that to make the best use of the available CPUs and memory (and other resources as used by the task.)

  • How can I get the memory allocation info of a java thread?

    Now I am going to write a program to monitor the execution condition of the java threads. But it seems that the classes in standard edition of JDK does not provide facilities to get the information such as the memory allocation and CPU time of a running thread. How can I do with it? Can I use JNI or JVMDI to get them? If it could do, how?

    Thanks a lot. I just browsed the specification of jvmpi. It is interesting and it seems that I can get the information I need. However, if I want to get the information in my program, I mean, if I want to build a class which may use JNI method to invoke the function written with JVMPI, and then forward the data to other upper layer objects, can it be done?

  • How to use Java threads in ColdFusion

    Hello Everybody,
    I have a question in concerns to threads. We all know that in
    CF8 we have this fantastic tag called <cfthread> which give
    us the ability to create assyncronous code, however, I was
    concerned about earlier versions of ColdFusion, like CF7 and CF
    6.1.
    How can I create a Java thread and use it in my CF code?
    Please, any help is much appreciated. Thanks in advance.
    Alvaro Costa
    Systems Analyst
    [email protected]

    A bean is obtain by <jsp:useBean> tag nd once bean is obtained we can get its property by using getProperty tag.

  • Use java thread? or Oracle DB scheduler?

    I have a java thread which purge records in a table every 30 seconds. The thread calls a prepared statement which is like "delete from MyTable where status=99"
    can I use DB's scheduled job to do the same thing? I can create a DB schedule, and a job in plsql.
    Thus I can save on DB connections.
    Which one is better in terms of performance?

    SoulTech2012 wrote:
    i personally recommend against PL/SQL if you can manage it
    some will argue that it's okay to couple yourself to a database because you're likely not to change it
    but i've seen enough migrations to know the painConversely I have seen attempts to process data by dragging it across the network in the vain attempt to make the application database agnostic. Which results in orders of magnitude more processing time when the application needs to do anything approaching real volume.

Maybe you are looking for

  • Adding a new reciever to an existing integration scenario of conf in PI7.0

    Hi SapAll. here i have got a requirement to add one more reciever to an existing integration scenario in Integration Directory(Configuration). this Integration scenario is for sending the idoc MATMAS.MATMAS05 From 5 Different SAP-R/3 Systems to 2 Rec

  • Calling Stored Procedure in SDK Code

    Hello Experts, Iam facing a problem in Sdk Code...How do i Excute the stored procedure in sdkcode.I have  aStored Procedure ,In My Stored Procedures (My Operation Is DML operation Insert),Inserting UDO (Document Data) To the Normal Table.   I am Havi

  • ImageIO - javax.imageio.IIOException: Can't get input stream from URL

    Hi, I'm developing a program which accesses a given URL of an image and saves it to a file. However when I try this I get the following error: javax.imageio.IIOException: Can't get input stream from URL!      at javax.imageio.ImageIO.read(Unknown Sou

  • Informatica Start Workflow failed in Workflow Manager

    Hi, I have just completed the installation of oracle BI Apps version 7.9.4 (Chapter 4 & 5 of installtion document). Now I am trying to run workflow using informatica workflow manager and i am getting below error in workflow log. It says "Cannot find

  • Collecting Notifications from multiple servers and applications

    Hi, I'm researching JMX technology for our Enterprise-wide monitoring needs. I've got a good understanding of how to create jmx connections and instrument resources for monitoring in a 1-to-1 jmx client to application scenario. However, I need to man