Dumb question about Thread Safety in Servlets

Hi all
I wrote this Client API for sending requests and receiving responses to / from a multivalue database. The API is called by my Servlet. Now it seems my API is not thread safe because when several people open up the servlet at the same time, the API gets totally confused. When the API calls are inside a synchronized(){} it works just fine, but obviously at a big performance hit. Is that the wrong way of doing it??
However when I was doing the ACID test locally on my machine, by opening two command prompts and excuting the same java program (with the same code in it as the servlet, but standalone) my API worked just fine. How come?
Any insights appreciated as I am just learning about thread safety now (the hard way :-( )
cheers
Dejan

Does this help
Are you using one connection to the database shared by all instances
of your servlet
And is this connection create in the init method of the servlet and stored
in the servlet context.
Problem 4 people try and use your servlet at the same time, each servlet trys to
create a connection to the database and then store it in the servlet context and
this causes a problem.
Solution create a listener to create the connection and store it in the servlet context
when the servlet is created.
If this is your problem it is not advisable to use only one connection to the db
try using db pooling

Similar Messages

  • Urgent question about Thread-safety

    Hi all,
    the new tiger release provides an "isReachable()" method for the "InetAddress" object.
    I've found, this method is not thread-safe (see the source and output below).
    It returns true for all threads, when multiple threads using this method with different adresses are running at a time and one of the addresses is reachable. This happens only on WinXp. Running on Linux, the output is like expected.
    I've tried to report this as a bug. But the gurus answered, taking care of thread safety would be a "programmers task".
    My question is, what can I do, to be thread-safe in my case?
    W.U.
    import java.util.*;
    import java.net.*;
    public class IsReachableTest_1 extends Thread{
        static volatile int inst=1;
        static final String NET_ADDR="192.168.111.";
        int instance=inst++;
        public void run(){
            for(int i=19;i<23;i++){
                try{
                    long start=System.nanoTime();
                    if(InetAddress.getByName(NET_ADDR+i).isReachable(1000))
                        System.out.println(""+instance+"--host found at:"+NET_ADDR+i+"--time:"+(System.nanoTime()-start)/1000000);
                    else
                        System.out.println(""+instance+"--no host at:"+NET_ADDR+i);
                }catch(Exception e){System.out.println(""+instance+"--ERROR "+e.toString());}
            System.out.println(""+instance+"--done.");
        public static void main(String[] args) {
            System.out.println(
                System.getProperty("java.vendor")+" "+
                System.getProperty("java.version")+" running on "+
                System.getProperty("os.name")+" "+
                System.getProperty("os.version"));
            Vector v=new Vector();
            System.out.println("\nTest 1: One after another:");
            for(int i=0;i<10;i++){
                IsReachableTest_1 t;
                t=new IsReachableTest_1();
                t.start();
                try{
                    t.join();
                }catch(Exception e){System.out.println("MAIN1: "+e.toString());}
            System.out.println("\nTest 2: All together:");
            inst=1;
            for(int i=0;i<10;i++){
                IsReachableTest_1 t;
                t=new IsReachableTest_1();
                t.start();
                v.addElement(t);
            for(Iterator i=v.iterator();i.hasNext();)
                try{
                    ((IsReachableTest_1)i.next()).join();
                }catch(Exception e){System.out.println("MAIN2: "+e.toString());}
                System.out.println("\nALL DONE");
    And here is the output, when running on WinXp:
    Sun Microsystems Inc. 1.5.0-beta running on Windows XP 5.1
    Test 1: One after another:
    1--no host at:192.168.111.19
    1--no host at:192.168.111.20
    1--host found at:192.168.111.21--time:2
    1--no host at:192.168.111.22
    1--done.
    2--no host at:192.168.111.19
    2--no host at:192.168.111.20
    2--host found at:192.168.111.21--time:4
    2--no host at:192.168.111.22
    2--done.
    3--no host at:192.168.111.19
    3--no host at:192.168.111.20
    3--host found at:192.168.111.21--time:1
    3--no host at:192.168.111.22
    3--done.
    4--no host at:192.168.111.19
    4--no host at:192.168.111.20
    4--host found at:192.168.111.21--time:1
    4--no host at:192.168.111.22
    4--done.
    5--no host at:192.168.111.19
    5--no host at:192.168.111.20
    5--host found at:192.168.111.21--time:3
    5--no host at:192.168.111.22
    5--done.
    6--no host at:192.168.111.19
    6--no host at:192.168.111.20
    6--host found at:192.168.111.21--time:1
    6--no host at:192.168.111.22
    6--done.
    7--no host at:192.168.111.19
    7--no host at:192.168.111.20
    7--host found at:192.168.111.21--time:1
    7--no host at:192.168.111.22
    7--done.
    8--no host at:192.168.111.19
    8--no host at:192.168.111.20
    8--host found at:192.168.111.21--time:1
    8--no host at:192.168.111.22
    8--done.
    9--no host at:192.168.111.19
    9--no host at:192.168.111.20
    9--host found at:192.168.111.21--time:1
    9--no host at:192.168.111.22
    9--done.
    10--no host at:192.168.111.19
    10--no host at:192.168.111.20
    10--host found at:192.168.111.21--time:1
    10--no host at:192.168.111.22
    10--done.
    Test 2: All together:
    1--no host at:192.168.111.19
    2--no host at:192.168.111.19
    3--no host at:192.168.111.19
    4--no host at:192.168.111.19
    5--no host at:192.168.111.19
    6--no host at:192.168.111.19
    7--no host at:192.168.111.19
    8--no host at:192.168.111.19
    9--no host at:192.168.111.19
    10--no host at:192.168.111.19
    2--no host at:192.168.111.20
    3--no host at:192.168.111.20
    6--host found at:192.168.111.20--time:924 <----- this host does not exist!!
    5--host found at:192.168.111.20--time:961 <----- this host does not exist!!
    10--host found at:192.168.111.20--time:778 <----- this host does not exist!!
    9--host found at:192.168.111.20--time:815 <----- this host does not exist!!
    2--host found at:192.168.111.21--time:37
    7--host found at:192.168.111.20--time:888 <----- this host does not exist!!
    8--host found at:192.168.111.20--time:852 <----- this host does not exist!!
    4--host found at:192.168.111.20--time:997 <----- this host does not exist!!
    1--host found at:192.168.111.20--time:1107 <----- this host does not exist!!
    3--host found at:192.168.111.21--time:38
    6--host found at:192.168.111.21--time:1
    5--host found at:192.168.111.21--time:1
    10--host found at:192.168.111.21--time:2
    2--host found at:192.168.111.22--time:3 <----- this host does not exist!!
    9--host found at:192.168.111.21--time:2
    7--host found at:192.168.111.21--time:1
    4--host found at:192.168.111.21--time:3
    1--host found at:192.168.111.21--time:39
    2--done.
    1--host found at:192.168.111.22--time:5 <----- this host does not exist!!
    1--done.
    10--host found at:192.168.111.22--time:40 <----- this host does not exist!!
    3--host found at:192.168.111.22--time:192 <----- this host does not exist!!
    6--host found at:192.168.111.22--time:75 <----- this host does not exist!!
    8--host found at:192.168.111.21--time:230
    5--host found at:192.168.111.22--time:155 <----- this host does not exist!!
    4--host found at:192.168.111.22--time:78 <----- this host does not exist!!
    9--host found at:192.168.111.22--time:77 <----- this host does not exist!!
    7--host found at:192.168.111.22--time:76 <----- this host does not exist!!
    10--done.
    6--done.
    4--done.
    5--done.
    3--done.
    7--done.
    9--done.
    8--no host at:192.168.111.22
    8--done.
    ALL DONE

    I created this test (it's basically the same as your class):
    import java.util.*;
    import java.net.*;
    public class IsReachableTest_2 implements Runnable {
        private final String[] addresses = new String[] {
             "www.sun.com",
             "129.42.16.99" // www.ibm.com which is not reachable
        public void run(){
            try {
                for (int i = 0; i < addresses.length; i++) {
                    final long start = System.nanoTime();
                    final String address = addresses;
         if (InetAddress.getByName(address).isReachable(5000)) {
         System.out.println(Thread.currentThread().getName() + ": Host found at: " + address +
              " --time: " + (System.nanoTime() - start) / 1000);
         } else System.out.println("no host at: " + address);
    } catch(Exception e){
    e.printStackTrace();
    System.out.println("Thread " + Thread.currentThread().getName() + " DONE");
    public static void main(String[] args) {
    System.out.println(
         System.getProperty("java.vendor") +
         " " +
         System.getProperty("java.version") +
         " running on " +
         System.getProperty("os.name") +
         " " +
         System.getProperty("os.version")
    for (int i = 0; i < 10; i++) {
         final Thread t = new Thread(new IsReachableTest_2(), "THREAD " + (i+1));
         t.start();
    And I get:
    Sun Microsystems Inc. 1.5.0-beta running on Windows 2000 5.0
    THREAD 1: Host found at: www.sun.com --time: 217653
    THREAD 3: Host found at: www.sun.com --time: 214404
    THREAD 6: Host found at: www.sun.com --time: 214900
    THREAD 4: Host found at: www.sun.com --time: 215901
    THREAD 5: Host found at: www.sun.com --time: 216666
    THREAD 10: Host found at: www.sun.com --time: 216620
    THREAD 9: Host found at: www.sun.com --time: 217405
    THREAD 2: Host found at: www.sun.com --time: 220705
    THREAD 7: Host found at: www.sun.com --time: 220845
    THREAD 8: Host found at: www.sun.com --time: 221384
    no host at: 129.42.16.99
    Thread THREAD 4 DONE
    no host at: 129.42.16.99
    Thread THREAD 6 DONE
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    Thread THREAD 5 DONE
    Thread THREAD 10 DONE
    Thread THREAD 9 DONE
    Thread THREAD 7 DONE
    Thread THREAD 3 DONE
    Thread THREAD 1 DONE
    Thread THREAD 2 DONE
    Thread THREAD 8 DONE
    HOWEVER: I was getting some strange results every so often. Results like:
    Sun Microsystems Inc. 1.5.0-beta running on Windows 2000 5.0
    THREAD 3: Host found at: www.sun.com --time: 261132
    THREAD 9: Host found at: www.sun.com --time: 264183
    THREAD 2: Host found at: www.sun.com --time: 266447
    THREAD 6: Host found at: www.sun.com --time: 266596
    THREAD 8: Host found at: www.sun.com --time: 267192
    THREAD 5: Host found at: www.sun.com --time: 268610
    THREAD 4: Host found at: www.sun.com --time: 269849
    THREAD 1: Host found at: www.sun.com --time: 280978
    THREAD 7: Host found at: www.sun.com --time: 272589
    THREAD 10: Host found at: www.sun.com --time: 273162
    THREAD 3: Host found at: 129.42.16.99 --time: 13657
    Thread THREAD 3 DONE
    THREAD 4: Host found at: 129.42.16.99 --time: 4123
    THREAD 2: Host found at: 129.42.16.99 --time: 9439
    THREAD 5: Host found at: 129.42.16.99 --time: 6681
    THREAD 8: Host found at: 129.42.16.99 --time: 7655
    THREAD 6: Host found at: 129.42.16.99 --time: 8627
    THREAD 9: Host found at: 129.42.16.99 --time: 10586
    Thread THREAD 4 DONE
    Thread THREAD 2 DONE
    Thread THREAD 5 DONE
    Thread THREAD 8 DONE
    Thread THREAD 6 DONE
    Thread THREAD 9 DONE
    no host at: 129.42.16.99
    Thread THREAD 7 DONE
    no host at: 129.42.16.99
    no host at: 129.42.16.99
    Thread THREAD 10 DONE
    Thread THREAD 1 DONE
    Usually the first run after I had compiled the class (!?) This isn't a thread safety problem.

  • A question about thread safety and the Acrobat SDK

    Hi All,
    On page 12 of this FAQ: http://www.adobe.com/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf
    It says that Use of any Acrobat product in a multithreaded way is technically impossible.
    I'm currently writing a command line application to perform some basic data gathering on a PDF file. The Application only makes use of a PDDoc object, and never calls on any other kind of object (i.e. AVDoc).
    The application itself is not multithreaded. All of the logic runs in a single thread.
    However, the application will be called (via the command line) from another application that /is/ multithreaded. I think that this might be fine, but I wasn't sure. In this case, would this count as a single thread, but spread across multiple processes? And if that is the case, would that be OK with the SDK?
    Or would having multiple invocations/calls into the Acrobat DLLs cause the same issue as a multi-threaded application?
    Unfortunately, I haven't done a lot of work with threads before. This might be a very silly question.

    The application would be called from a perl script that is used to automate several tasks. The app is a console application, written in C# w/ the Acrobat COM components, and Visual Studio 2005.
    The console application uses the Acrobat SDK to instantiate a PDDoc object, open a PDF, and get information about the document. It then returns results back to the console.
    So, the perl script just calls: "C:\pdfinfo.exe -f=myPdf.pdf" and pipes the result to a log file.
    In this case, it never creates a new instance of the Acrobat application, but it does use the SDK.
    The reason that I was concerned was that the perl script is multi-threaded. I wasn't sure if acrobat was just sensitive to multiple threads inside a single process, or if it was unable to handle multiple processes as well.
    PDL's answer suggests that I should be fine as long as a new process is started each time. This is good to hear.

  • Question about Threads/Servlets

    Let's say I have a servlet that opens a socket connection to a server application. On the server end, I would have to make a thread for each connection. But what about the Servlet? do I have to deal with Threads on the servlet side or does the servlet engine takes care of that?

    Unless your servlet implements the SingleThreadModel interface, the servlet container shoud take care of running each request to your servlet in a separate thread.
    Andy Nguyen

  • Question on thread safety with Sevlet action method

    I have an application that runs well but seems to have trouble with multiple users and I suspect that there is some thread safety issue involved.
    It is a Struts application and I have all of my execute methods of the Acton classes are all synchronized which I thought would take care of any cross user issues but it does not seem to have done that.
    The Action classes do have some instance variables which may be the problem as well as possibly a few utility string classes with static methods that are not synchornized. I keep some db connection cached in the session object but this should not be shared between users.
    My question is, with the execute method synchronized how or where could I be getting crosstalk between users (each with their own sessions)?
    I was thinking of packaging my Action class as seperate object with the actual Action class just allocate what I need (messages and locale) and pass them through a freshly instantiated "old action class". That should solve any instance variable cross talk.
    I am assuming that any local variables in the execute method would not have any exposure as they should be thread specific and allocated on the runtime stack for that thread call.
    Am I missing anything important?
    Thanks in advance
    ---John Putnam

         * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
         * using the currently configured parameters.
        public DocumentBuilder newDocumentBuilder()
            throws ParserConfigurationException
            /** Check that if a Schema has been specified that neither of the schema properties have been set. */
            if (grammar != null && attributes != null) {
                if (attributes.containsKey(JAXPConstants.JAXP_SCHEMA_LANGUAGE)) {
                    throw new ParserConfigurationException(
                            SAXMessageFormatter.formatMessage(null,
                            "schema-already-specified", new Object[] {JAXPConstants.JAXP_SCHEMA_LANGUAGE}));
                else if (attributes.containsKey(JAXPConstants.JAXP_SCHEMA_SOURCE)) {
                    throw new ParserConfigurationException(
                            SAXMessageFormatter.formatMessage(null,
                            "schema-already-specified", new Object[] {JAXPConstants.JAXP_SCHEMA_SOURCE}));               
            try {
                return new DocumentBuilderImpl(this, attributes, features, fSecureProcess);
            } catch (SAXException se) {
                // Handles both SAXNotSupportedException, SAXNotRecognizedException
                throw new ParserConfigurationException(se.getMessage());
        }It appears to be thread-safe. The 'attributes' and 'features' instances variables are hashtables, which are synchronized. Unless you are modifying DocumentBuilderFactory itself in another thread (say, changing whether it is namespace aware), I do not see any issues with a simple call to newDocumentBuilder().
    - Saish

  • Maybe a dumb question, about which power connectors to use, but....

    This may sound like an incredibly dumb question, but here goes anyway....
    I upgraded my system a few weeks ago, and will be slapping in a new ATI X850 Pro AGP card in a few days.  My current graphics card is a p.o.s. Radeon 9550, so it doesn't have its own power connector or even a fan.  My PSU is a dual-rail Antec model, and I'm wondering if it should matter any about how many or which devices I have connected to each power cable set.  My psu came with cables to attach, only 2 of the 4 though are the 4-pin molex - the other 2 are pci-e power connectors I believe.  Should it make a difference which or how many devices I connect to each cable?  For ease of plugging in, I believe my DVDRW and CDRom are using 1 cable, and my ide drive and floppy are using the other cable. Also, I have a pci fan and a case fan running off 1 or the other.  I'm likely to jump the power cable for the video card off the one the hard drive is using, unless someone has some suggestion to offer to the contrary.
    If it makes a difference, can anyone recommend how they would have them connect?
    My list of devices to plug in would be:
    1)IDE HDD
    2)Floppy
    3)CDRom
    4)DVDRW
    5)Case Fan
    6)PCI Fan
    7)Video Card
    Thanks for any thoughts!  SAB - you seem to be the man on builds.....any ideas? 

    Well, I put the new card in and connected it on a cable with the optical drives.  Also, I had unwittingly connected my cdrom on the same ide channel as my hdd    , so I changed that so both optical drives are on the secondary ide.
    So far, so good.  3dMark03 jumped up from 3300 with an overclocked Radeon 9550 to 10570 with the stock Radeon 850 Pro 
    I wish I could find some local source to purchase additional molex cords for my Antec SmartPower 2.0 psu, though - I've got 2 more 'outlets' just sitting there on the psu doing nothing, because the other cables are for pci-e, and I'm not using pci-e......  If I could buy some additional molex cables to plug in like the ones that came with it, I could have the vid card on its own cable....

  • A dumb question about wifi...

    I'm not as 'literate' as some are when it comes to computer technology...but here is the question...If I walk into a place that has wifi and my iphone is set with wifi ON, how will I know if there is a charge for using the wifi? Will my iphone automatically kick into the wifi or will there appear an invitation to pay a fee to connect...and how do you pay and do you have to have a password and if so, how do you get that? I know....dumb question...Thanks.

    Not a dumb question at all.
    First of all, set your iPhone up like this:
    1) Go to Settings on the main screen (looks like gears)
    2) Click on "Wi-Fi" (second option from the top)
    3) At the bottom of this page (Which should say "Wi-Fi Networks" at the top) turn "Ask to Join Networks" to the "ON" position.
    Now when you walk into a place that has Wi-Fi, your iPhone will display a little window that asks you whether you want to join the network or not.
    In some places, you may even see a list of more than one Wi-Fi network to join. This is quite common in New York City. The reason is because so many people have Wi-Fi in there apartments, and they all live so close together, that sometime your iPhone can detect multiple networks. The coffee shop near my apartment has their own network, but I can also connect to the Wi-Fi network in my apartment because I only live about 50 feet away.
    Anyway, when you see the list of Networks to join, you may notice a little padlock symbol next to some of them. This means these are closed networks that require a password to connect to. (My network is "Closed", ie requires a password so that everyone in the coffee shop next door doesn't use my internet).
    Networks that DO NOT have the little lock symbol are "Open" which means you can join them without a password. But there is a catch... A lot of coffee shops have open networks, but as soon as you try to browse the web, they redirect your browser to their own page, no matter what web address you enter. Basically, they are letting you connect to their network without a password, but not letting you browse the internet without giving them some money.
    So (as the previous poster said) the page that the coffee shops redirects you to, usually has instructions, and of course a place to put in a credit card. Once you do all that, then you can browse the internet without getting redirected to their little payment page. Its sort of confusing because you don't need a password to connect to their "open" network, but you do need one to browse any web pages. How you get the password differs from coffee shop to coffee shop, but usually they give it to you right inside your web browser once you give them your credit card number.
    T-Mobile provides wireless for Starbucks (at least in a lot of places they do). So once you have an account with t-mobile, you can use it in any starbucks or "T-mobile hotspot"
    Now this all sounds kind of complicated, but more and more these days, you can just walk into a place, find an open network (one without a lock next to it) and start browsing without being redirected or dealing with credit cards. Basically these places are providing free internet to try to attract customers.
    Good luck
    P.S. Wi-Fi eats up battery life. If you aren't going to be using it to browse web pages, you can go into settings, then Wi-Fi, and turn Wi-Fi off. This will save you battery life, but you have to remember to turn it back on. Even without Wi-Fi on, you can still browse the internet if you see a little "E" at the top of your screen. The E stands for the AT&Ts Edge network, which isn't as fast as Wi-Fi, but covers pretty much everywhere that your phone can get a signal.
    Message was edited by: erik graham

  • Dumb Question about multiple BSSIDs

    This is probably a dumb question, but enquiring minds want to know...
    When using Yosemite's built-in Wireless Diagnostics scan I see many unique WiFi BSSIDs (MAC addresses) associated with my Time Capsule: 5 for my Guest Network and 6 for my "main" network. I see that not all have the same 802.11 protocol, but not all have unique 802.11 protocols. Also I see my "main" network is the 802.11ac network.
    So my questions are:
    - Why are there so many different BSSIDs and how should I interpret them?
    - Which of these BSSIDs are "relevant" that I should pay attention to?
    Thanks,
    Kevin

    Why are there so many different BSSIDs and how should I interpret them?
    The 5 GHz band on the main network is one unique BSSID
    The 2.4 GHz band on the main network is one unique BSSID
    If you have the Guest Network setup......
    The 5 GHz band on the guest network is one unique BSSID
    The 2.4 GHz band on the guest network is one unique BSSID
    If you have multiple AirPort routers, repeat the information above for each router.
    Which of these BSSIDs are "relevant" that I should pay attention to?
    Personally, I pay no attention to this, but some users place great importance on this.
    The BSSID tells you which AirPort.....if you have multiple AirPorts....and which band....2.4 GHz or 5 GHz.....that you are connected to at the current time....as well as whether you are connected to the "main" network, or the "guest" network.....if you have enabled the guest function.

  • Dumb question about browser dectection

    I have a web application that looks awesome in IE but in Firefox it looks clunky and blocky. What I need to perform is a validation to see what browser the client is using. I have done this before on simple html pages javascript browser sniffing. Well it seems that I can't for the life of me to be able to get this working in Creator.
    My web project is a Sun Creator Web application. My OS is Windows
    Does anyone have any idea or references that you could supply to me?
    The following code works in an html environment but in a jsp I cant get the different style sheets to work.
    document.write("<link id="link1" rel="stylesheet" type="text/css" href="/WebDemoExtractor/resources/introductionFireFox.css" /> ");
    U jave tried many variations of the following
    document.write("<ui:link binding='#{introduction.link2}' id='link2' url='/resources/introductionFireFox.css'/>")
    I have tried performing many variations with the the above and I have had no success.
    Is it even possible to perform this function??
    Thank you

    jackiepanpan wrote:
    Not a dumb question at all.
    I think you mean how is it possible to view YouTube videos in Safari on iPad, right?
    Basically, YouTube senses the browser you're using. Because Safari on iPad doesn't support Flash, YouTube delivers the movie in a format the iPad can play (like H.264, as a previous post mentioned). This happens with YouTube videos embedded on other web sites, too.
    I hope this helps.
    I was in an Apple Store a few days ago, and a teenage kid really wanted an iPad. His dad said, "but it doesn't play flash, so you won't get to see YouTube videos that you love." Kid said, something expletive deleted.
    The son then picked up the iPad, and he clicked on the YouTube icon. Walked out of the store with it. Sales guy and I laughed. Made my day.

  • Dumb question about user_sdo_geom_metadata DIMINFO entries

    I'm sure that this is a dumb question!
    I create a new entry in user_sdo_geom_metadata as follows...
    INSERT INTO USER_SDO_GEOM_METADATA
    VALUES ( 'PR_A', 'GEOM',
    MDSYS.SDO_DIM_ARRAY(
    MDSYS.SDO_DIM_ELEMENT('X',190000.0,640000.0, 0.05),
    MDSYS.SDO_DIM_ELEMENT('Y',120000.0,680000.0, 0.05)
    NULL );
    But when I select the DIMINFO from the table...
    SQL> select diminfo from user_sdo_geom_metadata a where table_name = 'PR_A';
    DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
    SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', 190000, 640000, 0), SDO_DIM_ELEMENT('Y', 1200
    00, 680000, 0))
    The sdo_dim_element and sdo_tolerance
    elements show no decimal places.
    Is this because I have not set some
    display number format option in SQLPLUS
    or for some other reason?
    regards
    Simon

    Simon,
    If you are using an old sqlplus client
    (815) then you won't be able to see the decimal places in the diminfo object.
    But if you hace a newer (816/817) sqlplus
    client you should be able to see the decimal places.
    If you are not seeing them in these clients
    then there might be some format paramter set
    to show numbers without decimals.
    You can do a
    show numformat
    in sqlplus to see if there is any format set for that paramter.
    null

  • General question about thread-safe program

    Obviously in multi-user application, especially web-based application, we will need to consider thread safety. However, modern web servers and DBMS are already threaded, so to what extent the application programmer are freed from this worrying, and in what situation we must consider thread-safe in our code?
    Thanks

    if you use a J2EE compliant application server and write custom business object as enterprise beans, all concurrent access is handled by the server. however, if you code accesses resources concurrently, you need to handle this yourself. e.g. if a business class write to a file and multiple instances of this class in multiplt threads are running, you need to handle the access of these resources in your code (e.g. keyword "synchronized" or custom locking mechanisms).

  • Dumb question about cycling a battery. Sorry!

    I just received by new mac book pro replacement battery today and I have some questions regarding it. First of all, my original battery lasted 2 yrs, 2 mos. I purchased another apple battery for my 15 inch mac book pro (computer originally purch. Aug. 2007). I've seen on these boards that I'm supposed to "cycle" the battery once a week to get the maximum life out of it. I think a cycle means using the battery until it's power is used up and then charge up to 100% again. Is that right? Anyway, my question is, "What is the proper care for this new battery? Does it damage it to have it plugged in when it is fully charged? Or should I always keep it unplugged and use the battery until it runs out and then charge it again? And what does it mean to cycle it once a week, if I'm already using the battery and recharging it when needed?" Sorry if these are dumb questions. I'm not really computer savvy! Thanks.

    You should use the battery for a while every day but not drain it right down, before re-connecting the power and re-charging it to 95%+ this is not a complete cycle but partial/normal cycling.
    _Every couple of months_ you should re-calibrate the battery which means you keep using it until it goes into emergency sleep itself (you will see a warning then 5 minutes later it will go off by itself) and then _leave it in this state for at least 5 hours_ before you re-connect the power supply and fully charge it (without unplugging) - this is a proper re-calibration.

  • Questions about thread priority...

    Situation 1) setPriority(int adsa)
    public class ThreadPrioDemo1 {
          static class Demo1 implements Runnable{
          public void run(){ //blablabla}
         public static void main(String[] asdf){
              Runnable r = new Demo1();
              Thread myThread = new Thread(r);
              Thread mainT = Thread.currentThread();
              //mainT's priority is 5, so as myThread.
            mainT.setPriority(10);
    //mainT's priority to MAX, this simultaneously changes myThread to 10 as well.
            //or
            myThread.setPriority(10);
    //myThread priority to MAX, however, this does not change mainT to 10
    }Question 1), why if main Thread is set to a certain priority, the thread it creates automatically change its priority to the same as well, but the reverse is different??
    Situation 2) this is slightly more complex
    public class ImplementingRunnable {
         public static void main(String[] args) {
         Thread mainT = Thread.currentThread();
              for(int ii=0 ; ii<args.length ; ii++) {
                   Runnable r = new MyRunnable(args[ii]);
                   Thread t = new Thread(r);
                t.setDaemon(true);
                //t.setPriority(Thread.MAX_PRIORITY);
                   t.start();
    }and
    public class MyRunnable implements Runnable {
        public void test(){
        System.out.println("test");
         String message;
         public MyRunnable(String msg) {
              message = msg;
         public void run() {
              Thread me = Thread.currentThread();
              try {
                   for(int ii=0 ; ii<10 ; ii++) {
                       //case (1) me.setPriority(Thread.MIN_PRIORITY);
                        me.sleep(3);
                        System.out.println(message);
                        //case (2) me.setPriority(Thread.MIN_PRIORITY);
              } catch (InterruptedException ie) {
    }In class ImplementingRunnable, how is the commented code line related or counter-related with the commented case 1 code line in MyRunnable??
    Please help
    thanks

    Let me speak my question again very simply:
    1)
    Say I have two threads, 1 is main() thread, the program entry point, 2 is another thread created by main().
    Now, the default priority for both two is 5. If I change the priority for main() to a certain level, the other thread created by it automatically change its priority to the same level? why? and however, the reverse (in this case, if I change the priority for the thread created by main()) is not.
    2)
    public class Demo{
    static class MyThread implements Runnable{
    public void run(){//some thing}
    Thread t = new Thread(this);
    t.setPriority(10);
    public static void main(String[] afd){
    Runnable r = new MyThread();
    Thread t1 = new Thread(r);
    t1.setPriority(1);
    }What can you say about both bold code lines?
    If I use println() to track the Priority, the final priority, that is, t1, is 1. It is logical, however, the program behaves differently without the bold code line in the static class MyThread, despite the final priority for t1, is the same, 1.
    Any help by now??
    thanks alot

  • I'm a newbie: I have a question about threads

    midp 2.0
    Java SE 5.0
    J2ME version 2.2
    Below is my code I'm stucked with..... The code here shows a midlet class
    and another class derived from Thread (NetworkThread). This NetworkThread
    gets started from the main midlet... Search my code for the term ??????? and
    there you find my trouble area... What I'm having trouble with is that at
    that point in my code a NetworkThread has been given a url to access, and
    putting network access in the main thread is a bad thing because one can
    never know how long it takes to access the server... I want this line:
    System.out.println("NETWORK COMMINUCATION DONE"); to be processed after
    NetworkThread is done requesting the url.... I'm not sure how to solve this
    code so that the midlet waits for NetworkThread to access the url... But
    while NetworkThread access the url I want the midlet to response to user
    input, I don't want it to look like the midlet has crashed......
    Any tips on how I can solve this issue will be greatly appreciated...
    By the way, if you see anything else that could have been improved in my
    code, then please tell me about it too....
    MY CODE:
    NETWORKTHREAD:
    package com.test;
    import java.io.IOException;
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    public class NetworkThread extends Thread
    private boolean networkStop;
    private boolean networkPause;
    private HttpConnection httpConnection = null;
    private InputStream inputStream;
    private String Url;
    private String netCommand = null;
    private String netArg = null;
    private LoginForm loginForm;
    public NetworkThread(String serverURL)
      Url = serverURL;
    synchronized void requestStop()
      networkStop = true;
      notify();
    synchronized void resumeGame()
      networkPause = false;
      notify();
    synchronized void setCommand(String cmd, String arg)
      System.out.println("setCommand = " + cmd);
      netCommand = cmd;
      netArg = arg;
      networkPause = false;
      notify();
    void pauseThread()
      networkPause = true;
    public void run()
      networkPause = true;
      networkStop = false;
      while (true)
       if (networkStop) {
        break;
       synchronized(this) {
        while (networkPause) {
         try {
          wait();
         catch (Exception e) {}
       synchronized(this) {
         if (netCommand != null) {
           if (netCommand.equals("LOGIN")) {
             //Here some networking processing will
             //be done
         else if (netCommand.equals("LOGOUT")) {
         netCommand = null;
       pauseThread();
    THE MIDLET:
    package com.test;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.IOException;
    import java.lang.String;
    public class Test extends MIDlet
      private Display display;
      private NetworkThread networkThread;
      private String Url;
      public Test() {
        display = Display.getDisplay(this);
      public void startApp() throws MIDletStateChangeException {
        if (networkThread == null) {
          networkThread = new NetworkThread(Url);
          networkThread.start();
      else {
         networkThread.start();
    public void destroyApp(boolean unconditional) throws
    MIDletStateChangeException {
       public void pauseApp() {
       public void commandAction(Command c, Displayable s) {
         if (c == okCommand) {
           networkThread.setCommand("LOGIN", "arg1");
           System.out.println("NETWORK COMMINUCATION DONE");
    }

    You will probably need to learn about HTTP and XML to complete this project. If you don't know Java at all then I would suggest starting with tutorials like these ones first
    http://java.sun.com/docs/books/tutorial/index.html
    Have a happy day.

  • A question about threads

    Hi to everybody,
    I'm learning Java and I would like to know what's the difference between extending the Thread class and implementing the Runnable interface.
    Why when I run two objects that are instances of a Runnable class they seem to
    run concurrently, while when I run two objects whose class extends Thread, the virtual machine first executes the first thread , and only when the first thread has died it executes the second (the two threads have the same priority).
    I would also apreciate some clarifying information about "time-slicing" and the use of the method Thread.yield();
    thanks

    Main factor what desides whether to extend Thread or
    Implement Runnable is do you want to extend another.Sorry to say this but: WRONG!
    The main factor in a decision like this should be your model, i.e. is the class you are modelling really a sub-class of Thread, or - more likely - is it a task that should be able to run (on a thread or otherwise)?
    If you are in fact implementing a new kind of Thread (i.e. YourClass is-a Thread), then you extend Thread, otherwise you should implement Runnable.
    Ex:- If your class need to Extend another class then
    you cant extend Thread so you have to use Runnable.This is true, of course, but it should be done for the right reasons.
    So: implement Runnable (unless you are implementing a new kind of Thread)

Maybe you are looking for