How can I get to know if a method is threads-safe?

Hi, there.
How can I get to know if a method is threads-safe?
For example, in two different threads, is System.out.print() method safe or not?And where can I find the information with regard to this?
thanks very much.

System.out is a PrintStream object. None of the methods there use the synchronized modifier, but if you look in the source code, you will find out it is thread-safe, because it will use synchronized blocks whenever it writes some text.
The source code is in the src.jar file which you can extract.
I didn't find any comments about that PrintStream is thread-safe in the API.

Similar Messages

  • If I know a name of class , how can I get it's attribute and methods

    If I know a name of class , how can I get it's attribute and methods as well as it's detail information by ABAP code ?
    Best regards ,

    HI, Chandra ,
    Thank you very much , I can get the result
    Best regards,
    DATA lo_class TYPE REF TO cl_oo_class.
    DATA lt_attribs TYPE seo_attributes.
    FIELD-SYMBOLS: <attrib> TYPE vseoattrib.
    TRY.
        CREATE OBJECT lo_class
          EXPORTING
            clsname = 'CLASS_NAME'.
      CATCH cx_class_not_existent .
    ENDTRY.
    lt_attribs = lo_class->get_attributes( ).
    BREAK-POINT.

  • How can I get to know what's my iCloud account and password, I forgot them

    How can I get to know what's my iCloud account and password, I forgot them

    Welcome to the Apple community.
    If you can't remember the password, reset it at...
    iForgot.com

  • How can i get to know the widget type from the sample.

    If am trying to copy a widget sample from a reference site, how can I get to know if its a standard out of box or some custom widget.
    For example what type of widget could be the given, it seems its a google map for any location.

    Hello,
    Open the site for edit, in the side panel open the 'Content Catalog' and filter by 'Delivered with product' to see the list of the out of the box widgets.
    The Google maps widget is not an out of the box widget.
    Regards,
    Eliel.
    Cloud Portal Dev.

  • How can I get the InsertionPoint with FindText method.

    Hi All:
    In indesing script, I can find "abc text" with FindText method, and I want to insert a image here, but how can I get the insertionPoint(the FindText method return an object)? any help?
    Thanks in advance.

    What seems to be the problem?
    >app.findTextPreferences.findWhat = "text";
    >text = app.activeDocument.findText();
    >alert ("insertionpt "+text[0].insertionPoints[0].horizontalOffset);
    gives (as expected) the horizontal position of the first occurrance of "the".
    Note that findText returns an
    i array
    of found items; its length may be 0 (not found), 1 (only found once), or any other number.
    InsertionPoints is
    i also
    an array. Perhaps you expected it to be 'the' position of the found text -- it doesn't. It's an array of all insertion points in the found text.
    'The' position of the text (in its parent text) is something like text[0].index ("The index of the Text in the collection or parent object.")

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How to know whether a method is thread-safe through the java-doc?

    In some book, it says that SAXParserFactory.newSAXParser() is thread-safe,but in the java-doc,it doesn't say that.
    newSAXParser
    public abstract SAXParser newSAXParser()
    throws ParserConfigurationException,
    SAXExceptionCreates a new instance of a SAXParser using the currently configured factory parameters.
    Returns:
    A new instance of a SAXParser.
    Throws:
    ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
    SAXException - for SAX errors.
    I want to know, how to know whether a method is thread-safe?

    System.out is a PrintStream object. None of the methods there use the synchronized modifier, but if you look in the source code, you will find out it is thread-safe, because it will use synchronized blocks whenever it writes some text.
    The source code is in the src.jar file which you can extract.
    I didn't find any comments about that PrintStream is thread-safe in the API.

  • How can i get to know what is the reason for implausible meater reading?

    Hi All,
    I am new to this SAP -ISU.
    can any body tell me how can i get the reason for implausible meater reading.
    my requirement is to get the unbilled meters becasuse of unrealibility of meter reader.
    here what i understood is if meater reading is not in a position to bill so it means meater reading may be in implausible state. so i want to know the reason for implausible meater reading so that i get the meters which are not billed because of unreliasility of meter reader.
    in which table these reasons get store.
    if any body knows about these please reply me ASAP.
    Thanks in Advance.

    At the very least, you will receive EXACTLY the same product you sent in.  You may get a newer product.  It's Apple's choice.

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • How can i  get to know whether a ip Address is reachable?

    i am sorry for my poor english...now i meet a session:
    if i have very many ipaddresses,in system,we use ping to know
    whether the single ip is reachable,but in java application,how can
    i do it rapidly?
    thank u...

    There is a method named isReachable
    try to see its syntex and usage in java.net documentation
    bye

  • How can i get the name of a method

    i have a method which is calling another method.
    how can this submethod get the name from the main method?
    Thanks
    Thorsten

    There was a post about this a while ago, but I can't find it.
    Check out the getStackTrace method of Throwable (not the printStackTrace method). getStackTrace returns a StackTraceElement array. Each StackTraceElement has a getMethodName() method. In the returned array, the StackTraceElement at index 0 is the stack frame that the Throwable was created in, and the element at index 1 is the stack frame that your method was called from.
        public String getCurrentMethodName () {
            StackTraceElement[] st = (new Throwable()).getStackTrace();
            // Index 0 is the stack frame of "getCurrentMethodName"
            // Index 1 is the stack frame of the method that called this.
            // Index 2 is the stack frame of the method that called THAT.
            // Note that st[1] should always exist because this method
            // will always be called from another method (main, at very
            // least).  
            return st[1].getMethodName();
        public void myMethod () {
            System.out.println("The name of this method is " + getCurrentMethodName());
        };Hope that helps. I didn't test it, but it should work.
    Jason

  • How can I get Mail to include the entire conversation thread in a reply?

    Hi there,
    So, for work I end up having to manage all my email on the gmail website because people need to be able to see the entire thread and the Mail app doesn't seem to  include everything. It just replies with the most recent message and that's it.
    It works fine on the gmail website so I'm thinking this must be a thing in the Mail app.
    Is there a setting I can change in the Mail app to allow me to reply and include the entire thread by default?
    Thanks!

    Mail menu > Preferences... > Composing
    Choose the applicable preferences under Responding.
    If Mail does appear to show the entire thread, click the blue "See more from..." text at the bottom.

  • How can i get the name of the method or exception handle

    i just start to programm.
    i want to handle exceptions.
    there is a try catch procedure.
    i want that the catch procedures tells me which method has occured the exception.
    so i thought i could handle it like this
    public void getAllConstraints(Connection _conn){
    try{
    catch (SQLException e){
    handleException("SQLException", e);
    public void handleException(String exceptionName,
    Exception e){
    System.out.println(exceptionName + " occured in method " +
    GETMETHODENNAME);
    System.out.println("Exception name: ");
    System.err.println(e);
    the exceptionname should say for example SQLException, IOException or somthing like this.

    You can use the getStackTrace() method:
    StackTraceElement stack[] = new Exception().getStackTrace();
    // stack[0] is the current method
    // stack[1] is the calling method
    // etc.

  • How can i get to knw that my iphone is factory unlocked or not?

    How can i get to know that my iphone is factory unlocked or not?

    Hi
    I just discovered that the easiest way to find if the iphone you just bought is factory unlocked or not.
    Justcall up apple care of your country and tell them IMEI number. They willlet you know whether the iphone is factory unlocked or not.
    Easy isnt it? I wasted so many hours googling.

Maybe you are looking for