Question about synchronized static function.

Hi, everyone!
The synchronized statement often deals with an object (called monitor).
But a static function can be invoked without an object.
So if a static function is declared as static, what is the function of
static and synchronized here? Which lock it is using?
Can you give me a simple expplanation?
regards,
George

Hence try and avoid synchronizing static methods.
Try and use non static method if you are doing
multithreaded programming. That way you can have lockWell, I avoid static methods, not just when doing multithreading, but not for the reason you mention.
objects which allow non interfering methods to be
accessed in parallelThats easy to do with static methods anyway:
class Foo
  static Object lock1 = new Object();
  static Object lock2 = new Object();
  static void method1()
     synchronized( lock1 )
  static void method2()
     synchronized( lock2 )
}Maybe I just missunderstod you...

Similar Messages

  • Some question about the renegotiation function in SRM Contract (GOA)

    Hi All Expert,
    We are on SRM 5/4.6,  there is a question about the renegotiation function in SRM GOA.
    Can we renegotiate the price for some parts in the GOA items with this function ( e.g. Only renegotiate one item in the contract) ?
    Will the item price updated automatically after the renegotiation?
    Many thanks in advance!!!
        Wendrin

    Hi Sanjeev,
    Many thanks for your help.
    One more question, if I add a new item when we renegotiation, will it be transfered to contract and create a new item after that?
    Thanks and best regards
    Wendrin

  • Questions about user-defined functions

    Hello all,
    I've got some questions about user-defined function in a message mapping:
    1) How can I get the current date/time in format yyyy-mm-dd hh:mm:ss ? What is the java code for this?
    2) I want to use the StreamTransformation constant TIME_SENT, only this is not in the right time-zone.
    It is GMT and it should be CET (1 hour difference). How can I convert this in Java?
    Can somebody help me with this?
    Thanks in advance.
    Kind regards,
    Marco van Iersel

    Hi Marco,
    If the date format is fixed as you have mentioned,please use this:
                                    String test = "2009-03-27 23:15:30";
              String test1 = test.substring(11,13);
              if(!test1.equals("23"))
              int a = Integer.parseInt(test1);
              int b = a+1;
              System.out.println("b"+b);
              String c = Integer.toString(b);
                                    test = test.substring(0,10)+" " + c + test.substring(13,19);
                                    return test;
              if(test1.equals("23"))
              test = test.substring(0,10)+ " 00" + test.substring(13,19);
              return test;
                                    else return "";
    Kindly let me know if this works.
    Thanks.
    Regards.
    Shweta

  • A question about non-static inner class...

    hello everybody. i have a question about the non-static inner class. following is a block of codes:
    i can declare and have a handle of a non-static inner class, like this : Inner0.HaveValue hv = inn.getHandle( 100 );
    but why cannot i create an object of that non-static inner class by calling its constructor? like this : Inner0.HaveValue hv = Inner0.HaveValue( 100 );
    is it true that "you can never CREATE an object of a non-static inner class( an object of Inner0.HaveValue ) without an object of the outer class( an object of Inner0 )"??
    does the object "hv" in this program belong to the object of its outer class( that is : "inn" )? if "inn" is destroyed by the gc, can "hv" continue to exist?
    thanks a lot. I am a foreigner and my english is not very pure. I hope that i have expressed my idea clearly.
    // -------------- the codes -------------------
    import java.util.*;
    public class Inner0 {
    // definition of an inner class HaveValue...
    private class HaveValue {
    private int itsVal;
    public int getValue() {
    return itsVal;
    public HaveValue( int i ) {
    itsVal = i;
    // create an object of the inner class by calling this function ...
    public HaveValue getHandle( int i ) {
    return new HaveValue( i );
    public static void main( String[] args ) {
    Inner0 inn = new Inner0();
    Inner0.HaveValue hv = inn.getHandle( 100 );
    System.out.println( "i can create an inner class object." );
    System.out.println( "i can also get its value : " + hv.getValue() );
    return;
    // -------------- end of the codes --------------

    when you want to create an object of a non-static inner class, you have to have a reference of the enclosing class.
    You can create an instance of the inner class as:
    outer.inner oi = new outer().new inner();

  • Question about PL/SQL Function in report

    Hi all. I have a (basic) question about using a PL/SQL function in a report. In my report page I have an item (PL/SQL function) that has the following syntax:
    return username from t1
    where username like 'Le%'
    I reference this item in an email process. Ideally this function would return all usernames that begin with 'Le' in the drafted email; however, its not looping so I'm only getting a return on the first name.
    I have a few books on PL/SQL but I'm not exactly sure where to start - I imagine there is a loop process I need to integrate into the function but, like I said, I'm not sure.
    I would have posted this to the PL/SQL forum but also wanted some feedback on whether or not using this method is the best way forward. Essentially I have a table with usernames and just want to send email messages based on some simple logic.
    Thanks!
    Len

    Hi Sergio,
    First, it's an honor to have you reply to my post. Thanks!
    To be more specific,
    T1 is a table containing the results from a user security scan. Username is a column in this table containing user names. What I have done is create a page in HTML DB with the following elements:
    1. An 'Item' containing the PL/SQL function that is hidden. The purpose of this Item is to generate information from T1 that meets the simple logic parameters - in this case, the user names that begin with "Le". I have called this Item P145_TT
    2. A 'Process' containing references to HTMLDB_MAIL. The 'Process' looks similar to this:
    HTMLDB_MAIL.SEND(
    P_TO => '[email protected]',
    P_FROM => 'Anon Email Account',
    P_BODY => 'Note: This message was automatically generated. Do not attempt to reply to this email.
    These are the users that begin with Le: '||:P145_TT||' ',
    P_SUBJ => 'Summary');
    3. A 'Button' to submit the process and (hopefully) send the message containing all users that adhere to the logic in the function.
    4. If I use 'return username from t1...' I will get a username generated, but like I said previously, it only gives me the first and does not loop.

  • Question about "synchronized" and "wait"

    Hello, everyone!
    I have seen a piece of code like this,
    synchronized (lock)
    //do operation 1
    lock.wait();
    //do operation 2
    I think in the above piece of code, when a thead finished operation 1, it will release the lock and let other threads waiting for the lock have chance to run the same block of code. Am I correct?
    If I am correct, I have a further question, a "synchronized" block means a set of operations that can not be interrupted, but when invoke "wait" method, the thread running in the "synchronized" block will be terminated (interrupted) by release the lock and other threads will have chance to enter the "synchronized" block. In short, the execution inside the "synchronized" block will be interrupted. So, I wonder whether the above piece of code is correct and conforms to the principle of "synchronized". And what is its real use?
    Thanks in advance,
    George

    Thanks, pkwooster buddy!You're welcome
    I just wondered whether "wait inside a synchronized
    block" technology is thread safe. Please look at the
    following example,wait and synchronized are thread safe.
    public class Foo {
    int mVal= 0;
    public final Object mLock = ...;
    public void doIt() {
    synchronized(mLock) {
    mVal = ...;
    mLock.wait();
    if (mVal == ...) {
    // do something
    } else {
    // do something else
    }If we have two threads, T1 and T2, enter the block in
    their respective order, and T1 is woken up first, T2
    may have tampered with T1's execution path because T2
    changed mVal while T1 was asleep. So T2 manipulate
    instance field mVal is a side-effect.when you do the wait() you give up the lock and the other threads get a chance to run. When you exit the wait() you get the new value of the myVal variable which may have been changed. This is exactly what you want. To make that not thread save you could do
    int temp = myVal;
    wait();
    if(temp == ...)in this case the variable temp contains the old vale of myVal.
    >
    I think the most safest way is never wait inside a
    synchronized block, but it is less efficient. What do
    you think about the trick of wait inside a
    synchronized block? I think you are very experienced
    in thread field from your kind reply.
    Thanks in advance,
    Georgewait(), notify() and notifyAll() are very useful. You need them when you want threads to cooperate in an predictable manner. I recommend that you review the section on consumer and producer classes and wait and notify in the Threads Tutorial. It gives good examples. For a practical example of this you could also take a look at my Multithreaded Server Example. It implements a simple chat server that switches String messages. Look especially at the send(), doSend() and popMessage() methods in the StreamConnection class. These allow the receive thread of one user to send messages out using the send thread of another user. If you have questions about that example, please post the questions on that topic.
    Hope this helps.

  • Question about Custom Escalation Function

    I want to use a Custom Escalation Function described on this document:
    http://docs.tpu.ru/docs/oracle/en/owl/E14571_01/integration.1111/e10224/bp_workflow.htm#BACHEFDH
    I want to execute a custom function on task EXPIRATION.
    Main Question: The "Custom Escalation Function" is just for Escalation or i can use too for EXPIRATION ?
    Thanks.
    Victor Jabur

    Okay Experts. The problem is solved. There was no problem with the custom key figure function. The problem was with the sales order data. The sales order details for the material in question were under the "make to order" segment and the other transaction data info was in the "make to stock" segment.
    Once i found this out , i tried loading someother material and it worked perfectly.
    Thanks
    Aparna

  • Question about synchronized

    Hello everyone,
    Suppose I have a method which is a synchronized method (for example, method Foo in the following code block), and in this synchronized method another method which is not synchronized is invoked (for example, method Goo in the following code block). I am wondering when executing in Goo from Foo, whether we still have the synchronized feature (i.e. obtain the lock of "this" object).
    synchronized public Foo()
        Goo();
    private Goo()
    }Thanks in advance,
    George

    Kaj,
    Hi, pls see my post above - I replied to the same question in the other forum and I was pretty sure about my answer until I found it different from ur reply here.
    Here is my reply. Can u kindly guide me to what's wrong in it ?
    if a lock on a sync-ed method extends to all methods being called from it, then the jvm (bcos it has no means of knowing until runtime the method calls from a sync method) has to lock all the methods in a class that has atleast one sync method.
    What this would mean potentially is that the effect of sync-ing one method would be equal to sync-ing all the methods bcos any of the other methods could be potentially called from the sync-ed one.
    The example below is co-erced, but serves to illustrate the point.
         public class Test
        synchronized public  void Foo()
            Goo();
        synchronized public  void Moo()
            Goo();       
            notify();
        private void Goo()
            System.out.println(Thread.currentThread().getName()+" accessing goo");
            try
                if(Thread.currentThread().getName().equals("Th one"))
                     //force thread1 to wait , lets see if thread2 can access it while thread1's waiting on it
                    wait();
            catch(Exception e){}
            System.out.println(Thread.currentThread().getName()+" returning from goo");
    //first thread
    public class MyT implements Runnable
        Test t;
        public MyT(Test t)
            this.t = t;
        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
        public void run()
            t.Foo();
    //second thread
    public class MyT2 implements Runnable
        Test t;
        public MyT2(Test t)
            this.t = t;
        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
        public void run()
            t.Moo();
    //Main
    public class Main
        public static void main(String[] args)
            Test t = new Test();
            Thread th = new Thread(new MyT(t),"Th one");
            Thread th1 = new Thread(new MyT2(t), "Th two");
            th.start();
            th1.start();       
    And the o/p I got was
    Th one accessing goo/*thread one in goo, is in wait() coz of the funny if clause there*/
    Th two accessing goo /*there's no lock on goo, else with thread one in wait(), this wouldve been impossible*/
    Th two returning from goo/*Thread 2 is over with Goo(), will go back and notify Thread 1*/
    Th one returning from goo/*Thread 1 is notified, wakes up and returns :-)*/
    tx,
    ram.

  • I have a question about the Siri function.

    Here in Belgium, we speak Dutch and also French and English. But I think when you use the Siri function it is always easier to use it with your own language ( Dutch). 28th October, the iphone4S will be launched here in Belgium, but only with a Englisch version of the Siri function. So my question is that you have any idea when te Dutch version will be available in Belgium, or when i buy an iphone 4S with English version that I can update it to a Dutch version when it will be launched..
    Thank you for helping
    Dylan

    Nobody here can tell you anything more about Apple's plans than what they have already publicly stated, which is that more languages were promised for later (including Japanese, Chinese, Korean, Italian, and Spanish in 2012).

  • Question about calling a function.

    Im trying to call a function when a button is clicked, im using actionlistner() on the button, which looks as so :-
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            jButton1ActionPerformed.keyPad();
        }then trying to run this fuction when the button is clicked:-
    private void keyPad(java.awt.event.ActionEvent keyPad){
            String oldNumber;                           //set oldNumber to String
            String newNumber;                           //set newNumber as a String
            jButtonCall.setEnabled(true);
            jLabelInstruction.setText("Press 'Call' When Ready...");
            oldNumber = jTextFieldScreenDisplay.getText();      //get txt, if any, assign to oldNumber
            newNumber = oldNumber + "1";                        //set newNumber as oldNumber adding String to end
            jTextFieldScreenDisplay.setText(newNumber);         //Display newNumber
        }Im new, please go easy, everything is done in the main class, but would like to take this one stage further and create a seperate class outside the main, but i wan to get this working from within the main first.
    Cheers Guy's
    Doo

    So what is your question?
    Besides:
    - the things are called "methods"Hello There!
    Sorry, i'm trying to call a 'method'. I have buttons numbered 0-9 which enter into a text field once clicked using ActionEvent. At the moment each button has its own block of code which is a bad habit as its the same code over with one differance, the number value.
    Am i right in thinking i should create one method? Then calling this method on each button.
    The problem i have is i am unsure of the code to call the method within each buttons ActionEvent ie:-
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
             //call the method keyPad when button is clicked
    private void keyPad(java.awt.event.ActionEvent keyPad){
              //run this
    - if you define a method to accept a parameter, you
    actually have to provide a parameter upon calling
    that method.I don't understand???
    Thanks
    Doo

  • Question about "share screen" function

    When I am watching at another persons screen, is there a way to hover your mouse over the remote computers window without it effecting the pointer on the remote computer?
    Thank you

    kevinmathie wrote:
    Hi all,
    I'm recording vocals on a song that has lots of ritardandi and rubato. While the vocalist is here, we'll be setting her part of the tempo mapping in "stone," so to speak, but not necessarily the instruments' tempo mapping between her verses or before her verses.
    I usually record this kind of thing in Digital Performer, because I know that the audio sticks like glue to any ritardando, accelerando, etc., I may put in after recording the audio.
    My question: Does the "Follow Tempo" box in Logic let me program in ritards after the audio is recorded, without messing up how the audio is synced to the sequence?
    Yes.
    In other words, if the audio region spans bars 12-24, and I plug in a big ritard at bar 15, followed by "a tempo" in 16 after the audio is recorded, will the audio region follow the tempo mapping?
    Yes.
    +"Plug in a big ritard"+ ? You are one tough composer!
    2nd question: Does it do it automatically? Or, like Digital Performer, do I need to tell it to follow the tempo mapping after I change tempo?
    No, it 'responds' to tempo events in the *tempo track*.
    Any other tips/suggestions regarding this function that you feel would be helpful for me?
    Yep, it can eat up RAM. When you enable follow tempo for a track, the whole audio file is loaded into RAM. Use a utility like MenuMeters to keep an eye on RAM use. http://www.pure-mac.com/diag.html#menumeters
    You can find all relevant info on pages 526-527 of the *Logic Pro 8 User Manual*.
    regards, Erik.

  • Question About Unsupported Excel Function Workarounds

    Hi everyone! I hope this is ok to post something like this here. I haven't seen any rules against it so I am hoping I am able to. My apologies in advance if this is something I should ask in another location.
    My question / issue is in regards to the unsupported ISNA and ISBLANK functions in Excel. I can't seem to find a suitable workaround for XCelsius without using those two formulas in Excel and I am hoping someone here will be able to help or guide me.
    I have a cell that is for my input. If that cell has nothing in it I want Excel to continue to return the #N/A error as it is ignored and not shown in the List Box I have built in XCelsius. If there is a value input and it is not found in the Excel model I want it to return "No Record". Finally, if it is found then it will display the appropriate list of items.
    Any suggestions on a way to get this to function within Excel that will be compatible within XCelsius?
    Thanks in advance for your help everyone!

    Hi Aaron,
    both ISNA and ISBLANK are supported functions. The support for most IS() functions was added in SP1. They are not in the list in the help yet, but there should be the list of added functions in release notes. So, the following functions are supported:
    ISERR
    ISERROR
    ISEVEN
    ISODD
    ISLOGICAL
    ISNONTEXT
    ISTEXT
    TYPE
    ISNUMBER
    ISNA

  • Question about the GPS function

    I have just got my iPhone 3G, but still need to wait a couple of days to
    get my mobile number transferred.
    My question is: i don't have at the moment any mobile services from my provider.
    (No Service) I do have a WLAN connection. Should my GPS function in Google Maps still work? At the moment the icon is only spinning spinning and spinning....

    Thanks All!
    I turned it off and on again. waited a couple seconds outside (in the rain )
    And it is working great. 100% accurate
    Thanks Again.

  • Question about the alarm function.

    Has anyone used the alarm function on the iPhone?
    This may be a dumb question, but does the phone need to be in sleep mode, not shut off for alarms to work? If that is the case (I expect it is) would it be best to leave on while charging overnight for an early morning alarm to work properly?
    I think I've answered my own question, because I doubt an alarm can go off if the phone is off, but probably would if it was just asleep. Any thoughts on the alarm function in general?
    Thanks,
    CD3

    CD3, I would also assume the same but I do not really
    know the answer. To answer your question, yes. I use
    the Alarm function everyday thought I do not know why
    as I get up before the !@# thing wakes me up.
    Your answer is funny. I only need the alarm to wake me for a flight I'm taking to a show in Denver in Sept. Don't want to miss the flight because the alarm didn't work because the phone was completely off.
    So the non lazy way to answer my question...I'm going to try it myself. If it works one way or the other I'll mark my question answered and get myself a point or 2
    CD3

  • Question about SAP standard functionality related to the GL master record.

    My question is;
    Is this a SAP standard functionality to update the description ( long text or short) of a GL account (in master record) in one company code when we change the description of the same GL account in another company code which is assigned to the same chart of account?
    For example we have two company codes and both are assigned to the same chart of account and we are changing long text of one GL account in one CoCd. Should it update the long text of the same GL account in other CoCd assigned to the same chart of account? If so, then is this a standard SAP functionality or there is any setting where we can turn this functionality on or off.
    Thanks in advance for help n answer.

    Hi 
    GL accounts control takes place two leval
    1.Chart of account leval
    2.Comapany code leval
    In chart of account leval  Type/Description,Keywoard Translation,Information of Chart of Account of account tabs are controlled ,if u made any changes above tabs that should be applicable to all company codes using same chart of accounts.
    u r changing the short text,long text these are controlled by char of accounts leval this should be applicalbe to all company codes, u can't maintain company code leval type and description.

Maybe you are looking for