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.

Similar Messages

  • 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

  • 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.

  • I have an urgent question about my indesign. I had problems with the creative cloude app and then uninstalled it and then installed it again. Now it is not opening and I cannot download it again either. Pls give me help and advice if there is anything I c

    I have an urgent question about my indesign. I had problems with the creative cloude app and then uninstalled it and then installed it again. Now it is not opening and I cannot download it again either. Pls give me help and advice if there is anything I can do to repair it

    Please authorize ADE 3 with same credentials that you used with older version of ADE

  • 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

  • Urgent Question about System Center Server Names and Dashes

    Hey guys I have a quick Urgent question that would be awesome if it happens to get answered quickly :). 
    So in the past we had problems with different server names in components of System Center when setting up different servers.... I never myself saw the errors or what it did, but an absentee colleague did. For example is anything wrong with a name setup like
    xx-scom-01 / xx-scom-02  as compared to the standard scom01 scom02? We have a certain naming convention we are moving to and I wanted to see if this was fixed. I wanted to say it had something to do with the hyphens... anyways any foresight anyone can
    provide would be awesome. Thanks!

    Dashes in the name will work fine.
    Jonathan Almquist | SCOMskills, LLC (http://scomskills.com)

  • URGENT: Question about User_Exit

    Hello All,
    I have a question about user_exit. Does it share the same transaction context as the calling form??
    If it does, how to implement the same thing in Java.
    Any help or material available somewhere?
    TIA
    Naveen

    Naveen
    Actually what we are doing is converting Oracle Forms code into java code and i cannot open and change the code that is being called by the User_Exit built-in.
    So i want to know is how i can still keep the same functionality, without changing the Pro*C code into java, or some other native code.Since what you have in hand is an user exit I dont think you can use it straight away from Java Forms unless you do not have any Form specific things.
    In User exits we can do thigns like getting and putting values from/to oracle forms items and there are also provision to pass error and other related information between the forms and user exits.
    this is actually accomplished by having some internal API's ( these are invoked by the user_exit builtin in Forms) in Oracle Forms. And this is predefined and there is nothing much to know how this functionality works. And Oracle itself does not support User exits( if there is any interaction with Form) in Oracle Web Forms. And user exit has many Oracle specific libraries linked to it during compilation.
    Knowing this you should first know whether your user exit is Oracle Forms Dependent. If it is I think you dont have much options than rewriting your user exit.
    On the other hand if it does not , then I think you can easily get rid of the error and other handling information( if present in the user exit )and recompile it as a standalone Pro*C executable and the call it natively since it is noting but a C program in the compiled state.
    OK but regarding the connection you have to go back to Java and ask whether there is way to pass a conection context to a native C program( dont mention Proc or Oracle Forms here)
    So start finding whether your exit is Oracle Forms dependent. If not you can take it easy except for the connection thing which I am not . But if it is dependent then I think u have to start rewriting.
    Good Luck
    Vij

  • Urgent - Question about logging and debugging.

    Hi,
    I have a question about the logging and debugging supported by
    Weblogic 6.0. From what I understood by reading the documentation
    it has classes e.g. NotCatalogLogger class for logging the information.
    The class has one method callded
    debug() for writing the debugging information. I want to log the
    debug messages only in some situation. Can I control this using
    some property? Because the documentation says that the debug information
    is logged only if application is running in debug mode. Now how
    do I change the mode of an application??
    Thanks and Reagrds,
    Manoj

    Hi,
    I have a question about the logging and debugging supported by
    Weblogic 6.0. From what I understood by reading the documentation
    it has classes e.g. NotCatalogLogger class for logging the information.
    The class has one method callded
    debug() for writing the debugging information. I want to log the
    debug messages only in some situation. Can I control this using
    some property? Because the documentation says that the debug information
    is logged only if application is running in debug mode. Now how
    do I change the mode of an application??
    Thanks and Reagrds,
    Manoj

  • Quick (and urgent) Question about Intel G5's

    Just a quick question about the new intel G5's.
    I currently have bunch of software for my PPC G5 which is a Dual 2ghz. Software includes Adobe CS2, Macromedia Studio, Quark 6, etc, etc.
    If I purchase the new intel mac, would I be able to use the same software? or would I be forced to purchase a whole new set of everything I currently have?
    If the software will work on the intel G5, would it perform at the same rate/better than how it performs now on my PPC g5?
    Thanks in advance for any help.

    Rosetta:
    Most of the time you get a real 'hit' when a program first opens that is PPC. Very sluggish. They will require and use more memory than otherwise, too.
    Tests from last August aren't as helpful, there have been improvements, letting the Mac Pro pull even further ahead.
    http://www.barefeats.com/quad06.html
    Comparison Mac Models shows scores of all models. So there is 2x as much or more processing power, bandwidth, better video, as well as disk drives. A 'base' configuration would be 4-6GB RAM.
    And there are differences, more than between G4 and G5.
    People with experience would be Mac Pro Discussions
    Don't use Migration Assistant, and upgrade to CS3 etc. reinstall all your applications fresh.
    There are some drivers and plug-ins, that can be problems, and known.
    Mac Pro 2GHz 4GB 10K Raptor RAID Cinema HD   Mac OS X (10.4.9)   WD RE RAID Aaxeon FW800 PCIe MDD-G4 APC RS1500 Vista

  • Urgent questions about XMPL Standalone Deployment

    Hi,
    I've got some urgent questions from customer as below:
    1. Could XMLP be depoyed to BEA Weglogic?
    2. Could customer use Weblogic user to log on to XMLP?
    3. How is the performance of XMLP compared with other reporting tools?
    4. When will XMLP 5.6 release?
    Hope somebody can give me a hand!!!
    Regrads,
    Libra

    i am not sure abt the release date, but XMLP 5.6 Enterprise Edition comes with its own OC4J Component, refer to Mark Rittman's Blog for more details
    http://www.rittman.net/archives/2006/03/taking_a_sneak_peek_at_xml_pub.html

  • 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).

  • Urgent: Question about Censoring and replacing

    Hello, guys.
    This is my very first time writting a java program. Please tell me what I have done wrong as this is my first time?
    My question is to write a program that asks the user for a word to replace in some text, and the word to replace it with. The program then reads a line of text from the user and echoes the line back to screen replacing all occurrences of the first word with the second word. It only replaces the word being censored when it occurs independently in a line (i.e. not as a part of another word).
    Like:
    Enter word to censor: dumb
    Enter word to replace it: xxxxx
    Enter line of text to censor:
    The guy is dumb but his friend is even dumber.
    The guys is xxxxx but his friend is even dumber.
    Please look at my code now and tell me what is wrong?
    public class censor
       public static void main(String args[])
           String sentence = "Please type a word which you like to censor"
           String ac =  string sentence;
           String[] temp = null;
           temp = sentence.split(" ");
           for (int j = 0; j < temp.length; j++ )
               if (temp[j].equals("bridge"))
                   string sentence = "Censored";
               System.out.println(sentence + " " + string sentence);
    } Edited by: G on Apr 13, 2008 4:04 AM
    Edited by: KevinGupta on Apr 13, 2008 4:05 AM

    Hey guys,
    I'm getting an error where I have added the "ERROR LINE" next to the line where im getting an error..
    What I'm trying to do ?: I'm trying to make it like
    Enter word to censor: dumb
    Enter word to replace it: xxxxx
    Enter line of text to censor: The guy is dumb dumb dumb dumb and his friend is dumber.
    So, this code should replace ALL "dumb" with xxxxx NOT the dumber. But when I try to run this code only one dumb changes to xxxx not all ? So, please help on that. Also, this code doesnt work when I try to write " LIke ThaT " It gives me an exception error ?
    {color:#ff0000}Look at the error below (underneath the code){color}
    import java.util.*;
    public class LineCensor
    public static void main(String [] args)
    System.out.print("Enter a word to censor: ");
    Scanner keyboard = new Scanner(System.in);
    String word = keyboard.nextLine();
    System.out.print("Enter a word to replace it: ");
    String wordC = keyboard.nextLine();
    System.out.println("Enter line of text to censor: ");
    String phrase = keyboard.nextLine();
    String wordLowered = word.toLowerCase();
    String phraseLowered = phrase.toLowerCase();
    int location = phrase.indexOf(word);
    String string1 = phraseLowered.substring(location,(location +
    wordLowered.length()));
    String string2 = phraseLowered.substring(0, location);
    String string3 = phraseLowered.substring(location+word.length());
    System.out.println(string2+wordC+string3);
    string2 = string2.toLowerCase();
    for (int i=0; i < phrase.length; i++)
    (phrase.equals());                        <-------- ERROR LINE.
    phrase = wordC;
    System.out.println(+i);
    }ERROR:
    The error is:
    LineCensor.java:28: not a statement
    (phrase.equals());
    ^
    1 error ANOTher ErroR
    Enter a word to censor: CaT
    Enter a word to replace it: xxxx
    Enter line of text to censor:
    The cAT wAs CuRioUs abOuT otHER CAT's strings
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1932)
    at LineCensor.main(LineCensor.java:17) This error is coming up because of lower and high caps typing. This shouldnt be happening no matter how I type the sentence/word.
    Please help ?
    Edited by: kabootar on Apr 16, 2008 3:20 AM
    Edited by: kabootar on Apr 16, 2008 3:21 AM

  • 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.

  • Urgent question about 7200 rpm drive

    Ok I had a Hitachi 7k100 that I decided to swap for a momentus 7200.1. I am sitting here just getting ready to install it and I read the post about the black macbook getting so hot after this drive is installed.
    I know the hitachi runs fine but does anyone have a 7200.1 installed, that can still use this laptop on their lap? Also has anyone goteen some HD temps off this drive while in use in a Macbook?
    According to another thread there is a possibility that momentus drives use more wattage than they claim? I am going to hold off on opening the package for my drive until I hear what others experience with this drive has been.
    Kalel

    Hi Kalel,
    Similar position to you as I have a 7200.1 Momentus 100Gb sealed still awaiting it's new home. I'm starting to think maybe the Hitachi is a better bet based on this thread... http://discussions.apple.com/thread.jspa?threadID=497936&tstart=0
    In that thread I've asked around for other MacBook users experience with 7200RPM HD with interesting answers thrown back... I presume that has made you rethink the Momentus?
    I getting quite confused because I thought the Hitachi was quieter than the Seagate? Isn't it better for you to hold onto your Hitachi unless someone else could wave the flag for the Momentus proper? I can't give more weight to this until I'll try it on my one... hopefully in a few days.
    Alex

Maybe you are looking for