Multi-Thread application and common data

I try to make a multi-Thread application. All the Threads will update some common data.
How could I access the variable �VALUE� with the Thread in the following code:
public class Demo {
private static long VALUE;
public Demo(long SvId) {
VALUE = 0;
public static class makeThread extends Thread {
public void run() {
VALUE++;
public static long getVALUE() {
return VALUE;
The goal is to get the �VALUE� updated by the Thread with �getVALUE()�
Thanks for your reply
Benoit

That code is so wrong in so many ways......
I know you're just experimenting here, learning what can and can't be done with Threads, but bad habits start early, and get harder to kick as time goes on. I am going to give a little explanation here about what's wrong, and what's right.. If you're going to do anything serious though, please, read some books, and don't pick up bad habits.
Alright, The "answer" code. You don't use Thread.sleep() to wait for Threads to finish. That's just silly, use the join() method. It blocks until the threads execution is done. So if you have a whole bunch of threads in an array, and you want to start them up, and then do something once they finish. Do this.
for(int k=0; k<threads.length; k++) {
  threads[k].start();
for(int k=0; k<threads.length; k++) {
  threads[k].join();
System.out.println("All Threads Done");Now that's the simple problem. No tears there.
On to the java memory model. Here where the eye water starts flowing. The program you have written is not guarenteed to do what you expect it to do, that is, increment VALUE some amount of time and then print it out. The program is not "Thread Safe".
Problem 1) - Atomic Operations and Synchronization
Incrementing a 'long' is not an atomic operation via the JVM spec, icrementing an int is, so if you change the type of VALUE to an int you don't have to worry about corruption here. If a long is required, or any method with more then one operation that must complete without another thread entering. Then you must learn how to use the synchronized keyword.
Problem 2) - Visiblity
To get at this problem you have to understand low level computing terms. The variable VALUE will NOT be written out to main memory every time you increment it. It will be stored in the CPUs cache. If you have more then one CPU, and different CPUs get those threads you are starting up, one CPU won't know what the other is doing. You get memory overwrites, and nothing you expect. If you solve problem 1 by using a synchronized block, you also solve problem 2, because updating a variable under a lock will cause full visiblity of the change. However, there is another keyword in java.. "volatile".. A field modified with this keyword will always have it's changes visible.
This is a very short explaination, barely scratching the surface. I won't even go into performance issues here. If you want to know more. Here's the resources.
Doug Lea's book
http://java.sun.com/docs/books/cp/
Doug Lea's Site
http://g.cs.oswego.edu
-Spinoza

Similar Messages

  • Clarification of the handle/body idiom in multi threaded applications

    Hello
    As some DBXML classes use the handle-body idiom (handle/body idiom in some docs), could someone please clarify the consequences of that in a multi threaded application like a web container?
    For 100% Java people, like me, this is known in the Java world as 'programming towards interfaces', or as the Bridge pattern; which is seen as good practice.
    Let's take an example. The class XmlQueryContext is not thread safe, but it has a copy constructor. Imagine that your web application has one XmlQueryContext, that we never use in a query, but that we prepare only to be copied in new threads. Is it thus safe to instantiate various new XmlQueryContexts using that copy constructor in various new threads and use them simultaneously?
    Thank you
    Koen
    PS What I am really asking here is if somebody could please translate the following to Java parlé:
    A copy constructor is provided for this class. The class is implemented using a handle-body idiom. When a handle is copied both handles maintain a reference to the same body.

    As a Java user you do not have to worry about how the C++ copy constructors behave. In the Java API if a copy constructor exists for the object, then the copy constructor will copy all of the original object's data into a new object (XmlContainer is the one exception to this rule, generally one should not use that copy constructor at all). So in short, what you plan to do will work.
    Lauren Foutz

  • Immutable Objects in multi threaded application - how does it works?

    Hi
    I have this code will work in multithreaded application.
    I know that immutable object is thread safe because its state cannot be changed. And if we have volatile reference, if is changed with e.g.
    MyImmutableObject state = MyImmutableObject.newInstance(oldState, newArgs); i.e. if a thread wants to update the state it must create new immutable object initializing it with the old state and some new state arguments) and this will be visible to all other threads.
    But the question is, if a thread2 starts long operation with the state, in the middle of which thread1 updates the state with new instance, what will happen? Thread2 will use reference to the old object state i.e. it will use inconsistent state? Or thread2 will see the change made by thread1 because the reference to state is volatile, and in this case thread1 can use in the first part of its long operation the old state and in the second part the new state, which is incorrect?
    Therad1:                                                  Thead2:
    State state = cache.get();     //t1                  
    Result result1 = DoSomethingWithState(state);     //t1    
                               State state = cache.get(); //t2
       ->longOperation1(state); //t1
                               Result result2 = DoSomethingWithState(state); //t2
                                   ->longOperation1(state); //t2
       ->longOperation2(state);//t1
    cache.update(result1);    //t1             
                                   ->longOperation2(state);//t2
                               cache.update(result2);//t2
    Result DoSomethingWithState(State state) {
       longOperation1(state);
       //Imaging Thread1 finish here and update state, when Thread2 is going to execute next method
       longOperation2(state);
    return result;
    class cache {
    private volatile State state = State.newInstance(null, null);
    cache.update(result) {
       this.state = State.newInstance(result.getState, result.getNewFactors);
    get(){
    return state;
    }

    Please don't cross post
    http://stackoverflow.com/questions/6803487/immutable-objects-in-multi-threaded-application-how-does-it-work

  • Java Security Manager in Multi-threaded application

    I am writing a multi-threaded application listening (TCP and UDP) to several ports. To help implement certain security features (eg. refusing connections from certain ip address), I'm using the java.lang.SecurityManager (by subclassing it). I am having a few problems and queries and am hoping someone here can help me.
    1. As all the threads are calling the checkAccept(host, port) method. Is there a way to know which thread is currently accessing the security manager? For example if host A were to make 2 connections to the application, one to thread 1 (say listening to port 5001) and the other to to thread 2 (say listening to port 5002). I intend to refuse the connection to thread 2 but there is not way of differentiating the 2 connections since they are from the same host and there isnt any way of knowing their port number.
    2. Are calls to the Security Manager thread safe?
    I have been having this problem for a long time, would appreciate if someone can help point me to the right direction. cheers.

    1. As all the threads are calling the
    checkAccept(host, port) method. Is there a way to
    know which thread is currently accessing the security
    manager?Just use Thread.currentThread(). As specified in the Javadoc for e.g. SecurityManager.checkAccept().
    2. Are calls to the Security Manager thread safe? No.

  • Deploying large applications and common used classes

    I've got an application containing EntityBeans, statefull/stateless
    SessionBeans, and a Webapplication. Every component is packed in a jar File
    and all together in an EAR-File as an application.
    Those EJBs share some common classes, for example:
    EjbA in A.jar and EjbB in B.jar share a Helperclass C.
    Where do I put this class C? I try to avoid to put this class C in the
    Classpath of the application server. And when I put C in both jar-Files I
    got a ClassNotFoundException in one of the EJBs. I'm using WLS 6.0.
    Any ideas? Thanx in advance.

    FYI, this is fixed in 6.1
    Torsten Friebe wrote:
    Hi Daniel,
    thanks, this article answers my question. But does WLS 6.0 or 6.1 allready
    support J2EE Packaging as described in J2EE 1.3 Spec (PFD3) Chapter 8?
    Cheers
    Torsten
    "Daniel Hoppe" <[email protected]> schrieb im Newsbeitrag
    news:[email protected]..
    Hi Torsten,
    there is no really good solution so far. Check out this link, it
    elaborates this topic in detail.
    http://www.onjava.com/pub/a/onjava/2001/06/26/ejb.html
    Cheers,
    Daniel
    -----Ursprüngliche Nachricht-----
    Von: Torsten Friebe [mailto:[email protected]]
    Bereitgestellt: Freitag, 29. Juni 2001 11:59
    Bereitgestellt in: environment
    Unterhaltung: deploying large applications and common used classes
    Betreff: deploying large applications and common used classes
    I've got an application containing EntityBeans, statefull/stateless
    SessionBeans, and a Webapplication. Every component is packed
    in a jar File
    and all together in an EAR-File as an application.
    Those EJBs share some common classes, for example:
    EjbA in A.jar and EjbB in B.jar share a Helperclass C.
    Where do I put this class C? I try to avoid to put this class C in the
    Classpath of the application server. And when I put C in both
    jar-Files I
    got a ClassNotFoundException in one of the EJBs. I'm using WLS 6.0.
    Any ideas? Thanx in advance.

  • How can i improve speed of my application and reduce data transfer time ?

    Hello,
    My web application is adobe flex application which is build in flash builder 4.0 and use flex 4.0 SDK.
    I am using asp.net web service and cairngorm architecture in my project.
    Front : asp.net c# web project
    Middle : asp.net c# web service
    back : MS Sql server 2005
    When i run my applicaiton then i show that data transfer time between USA server to Indian client is so huge.
    Please suggest me all solutions approach so i am increase the speed of my application and reduce data transfer time.
    And please let me know how all approaches is reduce my data transfer speed.
    Thanks,
    Mohit.

    Hello,
    Thank you for your response,
    If i am using remote object insted of web services, can this will increase my application speed i
    It is big change so please give me guidance.
    My application have different type of request, some are very small request and transfer little amout of data from server to client, some request are send very huge amount of data from server to client .
    I am using JSON from data transfer in my current web service.
    Please provide some guidance on this.
    Thanks,
    Mohit

  • Multi-thread application recompile object with make but runs with old value

    Hi. I am working on a simulation in Java, and there is some behavior going on that I cannot understand. Granted, I'm a mechanical engineer, not a CS student (a fact that is probably made obvious by the code I'm posting below). The simulation comprises three parts: a controller, a robot, and a 3-d sensor. Here's the code for the "Simulation" application.
    class Simulation {
        void go() {
         ThreeDSensor sensorRunner = new ThreeDSensor();
         VSController controllerRunner = new VSController();
         KukaKR15SL robotRunner = new KukaKR15SL();
         Thread sensorThread = new Thread(sensorRunner);
         Thread controllerThread = new Thread(controllerRunner);
         Thread robotThread = new Thread(robotRunner);
         sensorThread.start();
         try {
             Thread.sleep(1000);  // Give sensorThread time to start in order to catch first triggers
         } catch(InterruptedException ex) {
             ex.printStackTrace();
         controllerThread.start();
         try {
             Thread.sleep(1000);  // Give controllerThread time to open the socket for communication with robotThread
         } catch(InterruptedException ex) {
             ex.printStackTrace();
         robotThread.start();
        public static void main(String[] args) {
         Simulation sim = new Simulation();
         sim.go();
    }I guess the big reason I'm using multi-threading is that once this simulation is working I want to be able to just run VSController alone and have it interface with a robot controller and a PC performing image processing. So with multiple threads I'm sending TCP and UDP messages around just like the final system will.
    I have made an object for my VSController that just stores values used by the simulation. That way I could have them all in one place instead of hunting through methods to change them. One example is "double noiseThreshold". Quickly, here is the code for "ControllerSettings.java".
    class ControllerSettings {
        final double cameraXOffset = 0;  // If > 0 then the origin of the camera CS is not on the center line of the lens
        final double cameraYOffset = 0;  // If > 0 then the origin of the camera CS is not on the center line of the lens
        final double cameraZOffset = 700;  // The distance that must be kept between the camera and the target
        // Error magnitude less than this is disregarded (in centimeters if roundingData else in millimeters)
        final double noiseThreshold = 60;
        final boolean estimatingEndPoints = false;  // If the controller is using two images per cycle then true
        final boolean roundingData = false;
        final boolean using3DData = true;  // How double[] sent from Matlab image processing is used
         * If the robot controller uses the output of this controller to command
         * motions in cartesian space then true.  This is used in two places: 1) initial guess of Jacobian,
         * and 2) "commandType" element sent to robot controller.
        final boolean useRobotControllerModel = false;
        final double thetaBumpValueForEstimationOfJacobian = .1;  // Distance each joint is jogged in estimation process
        final double bumpDistance = 50;  // Distance robot moves each time (magnitude of translation in mm)
        final double limitAngular = .5;  // Max amout robot joint will be commanded to rotate (in degrees)
    }And here is some pertinent code from "VSController.java".
    class VSController implements Runnable{
        ControllerSettings cSettings;  // Stores all the preferences used by the controller
        NGN controller;  // This is the controller algorithm.
        int dof;  // The degrees of freedom of the robot being controlled
        KukaSendData ksd;  // This provides communication to the robot.
        protected DatagramSocket socketForVisionSystem = null;
        ImageFeaturesData ifd;  // This parses and stores data from the image system.
        double[] errorVector;  // This is what's acted on by the algorithm
        PrintWriter errorTrackerOut = null;  // For analysis of error vector
        public void run() {
         VSController vsc = new VSController();
         vsc.go();
        public void go() {
         initWriters();
         cSettings = new ControllerSettings();
        public boolean isNoise() {
         boolean ret = false;
         double magnitude = 0;
         for (int i = 0; i < errorVector.length; i++) {
             magnitude += errorVector[i] * errorVector;
         magnitude = Math.sqrt(magnitude);
         if (magnitude <= cSettings.noiseThreshold) {
         System.out.println("VSController: magnitude (of errorVector) = " + magnitude +
                   ", threshold = " + cSettings.noiseThreshold); // Debug
    Now here's my issue: I change the value for "noiseThreshold" in "ControllerSettings.java" then run make from terminal (makefile code posted below) and rerun "Simulation". However, despite my changes to "ControllerSettings.java" the value for "noiseThreshold" is not changed, as evidenced by the output on the terminal screen:VSController: magnitude (of errorVector) = 6.085046125925263, threshold = 10.0 See, that value of 10.0 is what I used to have for noiseThreshold. I do not know why this value does not update even though I save the java file and execute make in between executions of Simulation. I would love it if someone could explain this problem to me.
    Here's the contents of makefile.
    JFLAGS = -cp ../Jama\-1\.0\.2.jar:../utils/:/usr/share/java/vecmath\-1\.5\.2.jar:.
    JC = javac
    .SUFFIXES: .java .class
    .java.class:
         $(JC) $(JFLAGS) $*.java
    CLASSES = \
         ControllerSettings.java \
         ImageFeaturesData.java \
         KukaKR15SL.java \
         ../utils/KukaSendData.java \
         NGN.java \
         Puma560.java \
         Robot.java \
         RobotSettings.java \
         Simulation.java \
         SimulationSettings.java \
         SixRRobot.java \
         Targets.java \
         TargetsSettings.java \
         ThreeDData.java \
         ThreeDSensor.java \
         VSController.java
    default: classes
    classes: $(CLASSES:.java=.class)
    clean:
         $(RM) *.classEdited by: raequin on Apr 5, 2010 1:43 PM

    I saw this explanation about what's causing my problem.
    "When the Java compiler sees a reference to a final static primitive or String, it inserts the actual value of that constant into the class that uses it. If you then change the constant value in the defining class but don't recompile the using class, it will continue to use the old value."
    I verified that the value updates if I also change something in VSController.java, forcing it to recompile. I think I will solve this problem by just making the variables in ControllerSettings no longer final (and then recompile VSController to make sure it takes effect!). Is there another solution? I saw intern(), but that seems to only apply to Strings.
    Thanks.

  • Question using Java API in a multi threaded application for MDX queries

    Currently I’m building a web application that makes a lot of MDX calls using the Essbase Java API. Each time we run an MDX call we basically run the following code:
    IEssbase ess = IEssbase.Home.create(IEssbase.JAPI_VERSION);
    IEssDomain dom = ess.signOn(userName, password, false, null, "embedded");
    IEssCubeView cv = cv=dom.openCubeView("view", hostName, appName, cubeName);
    IEssOpMdxQuery op = cv.createIEssOpMdxQuery();
    op.setQuery(false,mdx,false,IEssOpMdxQuery.EEssMemberIdentifierType.NAME);
    cv.performOperation(op);
    IEssMdDataSet mddata = cv.getMdDataSet();
    cv.close();
    My questions is, is this the correct way to use the API in multi threaded environment where many users may be hitting the application at the same time? For every request do I need to create a separate IEssbase object and sign on to an IEssDomain? Or can I use a single IEssbase and IEssDomain object for the entire application? If not should I call the IEssDomain.signOff() method after each user’s request has completed? Which of the above objects are thread safe? I’m using Essabae 9.3.1. Any insight would be really appreciated.
    Thanks
    David

    Thanks for the input friend,
    I should have mentioned that in my application all
    connections to Essbase use the same user name and
    password so the filtering isn’t a concern. This is my
    first Java application using Essbase has a data
    source, I’m used to connecting to various SQL
    databases and I always use a connection pool, how is
    connection pooling handled in the Essbase java API?I'm not sure what happened to it since I never used it, but there used to be something called the High Availability Services or something that was essentially a connection pool for Essbase JAPI connections, but it required an extra license.
    Since you don't care about identity (everyone has full access to everything), you can create your own connection pool, but you'll have to manage your multithreading yourself. Its been this way since the beginning. The C API isn't/wasn't thread-safe either (we tried).

  • Multi-threaded application crashing the VM

    Hi,
    I have a multi-threaded (about 120 threads) application which crashes without after running for a while.
    I get this in the windows event viewer
    Faulting application java.exe, version 0.0.0.0, faulting module kernel32.dll, version 5.2.3790.0, fault address 0x000017b1.
    Anyone knows why this would happen?
    - vineet

    Hi Alexis,
    Thanks for the response to my post!!
    Which version of the JVM?C:\>java -version
    java version "1.4.2_05"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
    Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
    Are you using the -server option?I was not using this option earlier but even on using this the jvm crashes after running for sometime.
    I am using these jvm options now -
    java -server -Xss128K -Xms256M -Xmx512M
    - vineet

  • Oracle Multi-threaded libraries and Forte R3

    Hello all,
    I heard through the grapevine that it would be possible
    to use Oracle 7.3 multi-threaded support with Forte 3.0G.
    (thus making Load-Balancing obsolete in this case)
    Has anyone given a try at this assumption ?
    If yes, on what platform and what versions ?
    Thanks,
    Vincent Figari
    You don't need to buy Internet access to use free Internet e-mail.
    Get completely free e-mail from Juno at http://www.juno.com
    Or call Juno at (800) 654-JUNO [654-5866]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi,
    It is available In R3.0.F.2 also. I tested it this release and it works
    very well. But, you need to make a design pattern on it : A Oracle
    Session can not be shared between several transactions throught threads.
    So You need to manage a pool of DBSessions.
    Hope this Helps,
    Daniel Nguyen
    Freelance Forte Consultant
    Vincent R Figari wrote:
    >
    Hello all,
    I heard through the grapevine that it would be possible
    to use Oracle 7.3 multi-threaded support with Forte 3.0G.
    (thus making Load-Balancing obsolete in this case)
    Has anyone given a try at this assumption ?
    If yes, on what platform and what versions ?
    Thanks,
    Vincent Figari
    You don't need to buy Internet access to use free Internet e-mail.
    Get completely free e-mail from Juno at http://www.juno.com
    Or call Juno at (800) 654-JUNO [654-5866]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>-
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Java multi-thread Applet and Multi-processor

    Hello,
    I have a JAVA applet which work fine on a mono-processeur machine and not fine at all on multi-processors.
    It use multi thread (for reading on socket) and some times, request are lost.
    Is that a matter of programming or a JVM bug ?
    This happens on Linux and Windows NT bi-processors.
    We hare using JAVA 1.3.0_02
    Thanks for your help
    [email protected]

    I have already have a look to javax.swing.SwingUtilities.invokeLater() but (I think) it don't work for my need.
    A graphic applet which create 2 threads : one for reading and one for writing on a socket.
    Request sent to the server are memorized in a vector, and once answer is received, the request is remove from vector and treated. Access to the list is protected by synchronize.
    Everything works fine one several plateforme (linux, windows 98/2000/NT, Solaris). The only problem is on multi-processor : request are lost !

  • Does Firefox 13 run in a multi-threaded mode and can it utilize quad-core processors?

    When purchasing a new PC, one chooses between dual-core vs. quad-core processors and some people claim that Firefox run in a mulch-threaded mode and treats each tab as a separate process and that it can fully utilize the advantage of a quad-core processor. Is that true?

    Firefox doesn't treat each tab as a separate process. While this may be a feature sometime in the future, I don't know of any plans to introduce it anytime soon. Obviously, buying a quad core processor is going to be significantly faster than a dual-core, and your browser is usually less resource intensive than many other programs. I wouldn't use it as your purchasing decision. Firefox will run equally well on a dual-core or a quad-core, but windows and other programs will run better with 4 cores.

  • Error when using same QueueSession in a multi threaded application

    I have deployed a OSSJ Trouble Ticket refererence Implementation on Sun Java System App Server Platform Edition 8.1 default server.
    The TT server listens on queue MessageQueue and sends its reply on MessageReplyQueue
    The application that sends the request to the TT server should support concurrent requests using threads.
    The sender application creates a QueueConnection and a QueueSession.
    This QueueSession is shared by all the threads that send the request to the TT server.
    Each thread creates its own QueueSender, TemporaryQueue which is set as replyTo in the message, QueueReceiver using the TemporaryQueue in the run method
    When the application is run multiple times i get the following exception
    javax.jms.IllegalStateException: [C4055]: Resource in conflict. Concurrent operations on a session.
    at com.sun.messaging.jmq.jmsclient.SessionImpl.setInSyncState(SessionImpl.java:2177)
    at com.sun.messaging.jmq.jmsclient.SessionImpl.acknowledge(SessionImpl.java:972)
    at com.sun.messaging.jmq.jmsclient.MessageConsumerImpl.receive(MessageConsumerImpl.java:375)
    at com.sun.messaging.jmq.jmsclient.MessageConsumerImpl.receive(MessageConsumerImpl.java:347)
    at xvt.tt.MessageSenderMultiThread.run(MessageSenderMultiThread.java:112)
    The code looks as follows
    public class MessageSenderMultiThread extends Thread {
    private String strMessage = null;
    private QueueSender queueSender = null;
    private QueueReceiver queueReceiver = null;
    private TextMessage message = null;
    private TemporaryQueue tempQueue = null;
    private QueueConnection tempQC = null;
    private QueueSession tempQS = null;
    private Queue tempQ = null;
    String inputQname = "MyQueue";
    String outputQname = "A";
    private int sleepTime;
    static InitialContext jndiContext = null;
    Queue replyQueue=null;
    Hashtable sessions=null;
    static QueueConnection queueConnection = null;
    public static String readFromFile(String fileName) {
    String line = null;
    try {
    FileReader fr = new FileReader(fileName);
    BufferedReader br = new BufferedReader(fr);
    String temp = "";
    line = "";
    while ((temp = br.readLine()) != null) {
    //System.out.println("line is"+line);
    if (temp != null)
    line = line + temp;
    return line;
    } catch (Exception ex) {
    System.out.println("Exception occurred,Ex" + ex);
    return line;
    MessageSenderMultiThread(String strMsg, int sTime, QueueConnection qC, QueueSession qS, Queue q, String name) {
    super(name);
    this.strMessage = strMsg;
    this.sleepTime = sTime;
    this.tempQC = qC;
    this.tempQS = qS;
    this.tempQ = q;
    sessions=new Hashtable();
    System.out.println("Inside Constructior");
    public void run() {
    try {           
    queueSender = tempQS.createSender(tempQ);
    tempQueue = tempQS.createTemporaryQueue();
    queueReceiver = tempQS.createReceiver(tempQueue);
    //queueReceiver = tempQS.createReceiver(replyQueue);
    message = tempQS.createTextMessage();
    message.setText(this.strMessage);
    message.setJMSReplyTo(tempQueue);
    //message.setJMSReplyTo(replyQueue);
    message.setJMSCorrelationID("1234");
    queueSender.send(message);
    System.out.println(message.getText());
    tempQC.start();
    //while (true) {
    Message m = queueReceiver.receive();
    if (m != null) {
    if (m instanceof TextMessage) {
    message = (TextMessage) m;
    if (message != null) {                           
    System.out.println("########################corr id::"+message.getJMSCorrelationID());
    queueReceiver.close();
    //System.out.println("message:: " + message.getText() + "Thread Name " + this.getName());
    } else
    System.out.println("NULL");
    } //else
    //break;
    System.out.println("Exiting !");
    } catch (JMSException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    public static void main(String args[]) {
    String inputQname = "System/RI/ApplicationType/TroubleTicket/Application/1-0;0-0;OSSJTTRI/Comp/MessageQueue";
    QueueConnectionFactory queueConnectionFactory = null;
    QueueSession queueSession = null;
    Queue inputQueue = null;
    try {
    jndiContext = new InitialContext();
    queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("System/RI/ApplicationType/TroubleTicket/Application/1-0;0-0;OSSJTTRI/Comp/QueueConnectionFactory");
    inputQueue = (Queue) jndiContext.lookup(inputQname);
    queueConnection = queueConnectionFactory.createQueueConnection();
    queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    String strRequest = null;
    strRequest = readFromFile("C:/ISM/getTroubleTicketsByKeysRequest.xml");
    new MessageSenderMultiThread(strRequest, 100, queueConnection, queueSession, inputQueue, "Thread1").start();
    strRequest = readFromFile("C:/ISM/getTroubleTicketsByKeysRequest1.xml");
    new MessageSenderMultiThread(strRequest, 100, queueConnection, queueSession, inputQueue,"Thread2").start();
    System.out.println("OVER");
    // System.exit(-1);
    }

    A session is single threaded (so it can not be used by different threads and generate valid behavior). This behavior is covered in @ setion 4.4 of the JMS specification
    If you need multiple threads to process messages you should either:
    * have them share a single session
    * read messages in from the session in a single thread and pass them off to
    other threads processing the message
    On the second option, you must have the "reading" thread also acknowledge the message in client acknowledge (or commit in transactions)

  • IPhoto application and camera Date differ!

    Lately many photos I import from my digital camera come up wrong in the iPhoto application.
    My camera (Cannon PowerShot A590) shows the right date, but iPhoto sets the "roll" date as :
    14/1/ 2008 to 21/31/2008
    One of these photos date shows as 21/21/2008
    I didn't notice this until I imported a roll, and tried to change it in the information box for each photo, but the date I typed in didn't save and reverted to the 21/21/2008.
    I can not find any place in the iPhoto "help" to correct this date problem. I can not change the date when I am trying to import a roll.
    What gives, how did this happen, since there is NO month of 14 or 21 ???
    Please advise quickly, thanks.

    Daniel:
    If you want to correct the date in the file itself, thus allowing other applications to have and use the correct date, then you'll have to export those files to a folder on the desktop and batch change the EXIF date with PhotoInfo. You can then import them again into iPhoto and delete those with the incorrect date. This will not create a compressed file as all you're doing is copying the file to the desktop, editing the date field and then copying back to iPhoto.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've written an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • C++ Application and Oracle Data Source

    Hi everyone,
    I am a bit of a newbie in this domain so am a bit confused with some of the options I have for my task. My task is to have a C++ application which will write/read/update data to/from an Oracle database. What are my options in this case?
    I have read about OCI and OCCI, about ODBC drivers etc. but how does it fit in. If I use OCI or OCCI, do I need an ODBC driver (since from what I have seen, these aren't available for free and free is also one of the requirements)? If not, what do I need to be able to use OCI or OCCI?
    If I am wrong and there are free ODBC drivers for Linux, where can I find them?
    Or does this whole question sound like garbage? :(
    Thanks in advance.

    Hi,
    This is my experience, if you know for sure that your application is going to execute always against a Oracle Data source, perhaps you shouldn't use ODBC and you should go for OCCI. This should be a good starting point:
    http://www.orafaq.com/faq/oci
    And here is another question, how can I set up a development environment to compile a C++ application (written using ODBC) on a Solaris server? I need the headers and the library against which I have to link the application. My Oracle database is 9.2.0.4.0.
    Any help will be appreciated. Thanks!

Maybe you are looking for

  • Iphoto will not burn to cd

    When burning cds with iphoto 2.0.1 , I get an unknow error(-2147352480) when the burn is finishing causing a failure. Anyone know how to correct this malfuntion. thanks degoodwin

  • Wrapper.Classpath and NFS issue

    Using Jserv1.1.2 It seems that there are Issues When you try to create wrapper.classpath that points to a mapped Network drive using NFS protocol. It result in a Internal Server Error Did someone encounter same issues?? Thanks to answer.

  • Trouble querying v$archived_log

    Hi Gurus. I am trying to use the v$archived_log view to check the last applied (it must be applied) archivelog to our standby. This works with the following: SELECT SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG WHERE APPLIED = 'YES'; The above provides me w

  • Cant remember iCloud account password???

    OK so... My boyfriend and I share an iPad. My Apple ID is currently being used for most things on the iPad but my boyfriend made the iCloud account in his email so anyways now the guy can't remember the password, security question answer OR the passw

  • Large pool size

    Hi, how to resolve the problem ORA-04031 my SGA is 504439252 455124 478150656 25165824 667648 java_pool_size 159383552 large_pool_size 16777216 shared_pool_reserved_size 10485760 shared_pool_size 209715200 This problem occurred when export full the D