Doubt: About synchronized methods?

Hi,
Can any one let me know, Is there any difference between static and non-static synchronized methods? If yes, what is the difference?

One is static and one isn't. What did you think?
As I recall, non-static methods lock on the object, whereas static methods lock on the class object, if that's what you're wondering about.

Similar Messages

  • About synchronized method

    When there are codes like below...
    class A{
    synchronized calculate(){
    class B{
    public void search(){
    A a = new A();
    a.calculate(); ------- 1
    do something --------- 2
    When I call synchronized method such as number 1,
    number 2 is waiting until number 1 is finished, otherwise number 1 starts with
    another thread and number 2 is executed in regardless of number 1?
    please let me know.
    In my experience, number 2 is executed in regarldess of number 1.
    thanks in advance

    public class Syn {
    Vector test = new Vector();
    public synchronized void method1(){
    try{
    Thread.sleep(100);
    }catch(Exception e){
    System.out.println("## test =--------> "+test);
    public static void main(String[] argv){
    Syn syn = new Syn();
    SynThread thread = new SynThread(syn);
    thread.start();
    syn.method1();
    syn.test.add("jongha");
    syn.test.add("is good");
    static class SynThread extends Thread{
    Syn syn = null;
    public SynThread(Syn syn_){
    syn = syn_;
    public void run(){
    syn.method1();
    in this code, I got the result like this
    ## test =--------> []
    ## test =--------> [jongha, is good]
    when a thread is waiting for finishing synchronized method,
    that waiting thread do execute next code without waiting finishing synchronized method.
    thanks

  • Doubt about synchronized

    I have the following code:
    public class MySingleton {
         Hashtable<String, String> htTable= new Hashtable<String, String>();     
         private static int counter=0;
         protected static MySingleton myInstance;
         private MySingleton()
              super();
         public synchronized static MySingleton getInstance()
         if (myInstance==null)
              myInstance=new MySingleton();
         return myInstance;
         protected String getCounter()
              counter++;
              return new Integer(counter).toString();
         public void add(String id, String value)
              // update tables
              htTable.put(id, value);
         public void remove(String id)
              htTable.remove(id);
    Several threads will do something like:
         MySingleton ms=MySingleton.getInstance();
         ms.getCounter();
         ms.add(id1);
         ms.remove(id1)
    My questions are:
    1- Must "getCounter" method be synchronized ?. I think it should if it is not atomic... but I am not sure if it
    is atomic or not.
    2- Must "add" and "remove" method be synchronized ?. Take into account that in my application, every thread will
    remove only the elements that it added. So, it is not possible that thread X removes an entry that another thread
    added previously.
    Thanks.

    As the other posters have noted, Hashtable implements its own synchronization, so your add and remove methods could get by without the synchronized keyword. There is a small advantage to using HashMap and explicitly synchronizing the methods as an alternate approach... Mainly, that the intentions of the code will be more readily apparent to somebody who reads it in the future. Not everyone realizes that Hashtable is synchronized (a feature which is as much an historical artifact as anything).
    Also, you should either declare getCounter() as synchronized or use an AtomicInteger for your counter.
    Finally, you may find it interesting to go to Wikipedia and read about "The solution of Bill Pugh" for implementing singletons
    http://en.wikipedia.org/wiki/Singleton_pattern#The_solution_of_Bill_Pugh

  • Doubt about generic method

    i have a generic method has shown below
    public static <E extends Number> <E>process(E list){
    List<Interger> output = new ArrayList<Interger>(); or List<Number> output = new ArrayList<Number>();
    return output ;
    if delcare the output variable using Interger or Number . when i am returning the output . it is showing me compiler error and it suggests me to add cast List<E>. Why i not able understand. please clarify my doubt.
    Thanks
    Sura.Maruthi
    Edited by: sura.maruthi on Sep 21, 2008 9:48 PM

    Your method declaration is garbled; there can be only one <...> clause, eg
    public static <E extends Number> E process(E list);This declaration says that for any subclass E of Number, the method process takes a single E instance (called list!?) and returns a single E instance. A valid implementation would be
    return list;I'm guessing you want the parameter to have type List<E>?. Like this:
    public static <E extends Number> E process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns a single E instance. A valid implementation would be
    return list.get(0);Or perhaps you also want to return a list of numbers?
    public static <E extends Number> List<E> process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns another list of E's. A valid implementation would be
    return list;Note that you cannot just return a list of Integers or Floats, because your generic method must work for any subclass of Number, and you're promising to return back a list of the same type as the argument passed in.
    Edited by: nygaard on Sep 22, 2008 10:05 AM

  • Technical doubt about setBounds() method

    Hi all.
    I have a little doubt. I don't completely understand the behaviour of setBounds() method of a JComponent extending class.
    I prepared a little test application to explain this doubt. Here it is:
    import javax.swing.*;
    import java.awt.*;
    public class TestSetBounds extends JFrame{
        JPanel myPanel = new JPanel();
        MyComponent myComp = new MyComponent();
        public TestSetBounds() {
            super("SetBounds Test");
            setSize(480, 320);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myPanel.add(myComp);
            setContentPane(myPanel);
            setVisible(true);
        public static void main(String args[]) {
            TestSetBounds tsb = new TestSetBounds();
    class MyComponent extends JComponent implements Runnable
        // setting dimension properties
        int compWidth = 25;
        int compHeight = 50;
        // these values are for testing
        int xStart = 490;
        int xEnd = -12;
        Thread t;
        public MyComponent()
            super();
            setOpaque(true);
            setVisible(true);
            if (t == null)
                t = new Thread(this);
                t.start();
        public void paintComponent(Graphics g)
            super.paintComponents(g);
            setBounds(xStart, 160, compWidth, compHeight);
            Graphics2D area2D = (Graphics2D) g;
            area2D.setColor(Color.RED);
            area2D.fillRect(0, 0, compWidth, compHeight);
        public Dimension getPreferredSize() {
          return new Dimension(compWidth, compHeight);
        public Dimension getMaximumSize() {
          return getPreferredSize();
        public void run()
            for(   ; xStart > xEnd; xStart--)
                repaint();
                try
                    {t.sleep(10);}
                catch (Exception exc) {}
    }   I tested two situations:
    a. Setting xStart = 100 and xEnd = -12, the application run how I expected. With negative value of x coordinate, my component is painted starting out of panel. We only can see my component portion which remains on the panel.
    b. Setting xStart = 490 and xEnd = 300. My component is initially painted out of panel, like test a. During for-cicle, xStart value decreases, entering the panel width value. At this point I must see the component portion which remain on the panel.But the component seems not be painted.
    Why this behaviour?
    Thanks,
    Massimiliano

    Your immediate problem can be solved by making two changes:
    a) your component has no initial size:
    setSize(25, 50); // this is new
    setOpaque(true);
    setVisible(true); // not requiredb) use setLocation() to reposition the component
    setLocation(xStart, 160);
    //repaint(); // not required since changing the location will cause a repaintHowever the code still has many areas of concern.
    For example, after the component has stopped moving, resize the frame. Notice how the component jumps to the top and middle of the frame? This is because by default a JPanel uses a LayoutManager. When you resize the frame the LayoutManager is invoked and the component is positioned based on the rules of the LayoutManager.
    So, you need to read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]Using Layout Manager to understand the difference between using a Layout Manager and using "Absolute Positioning" (which is what you are attempting to do).
    You should not be altering the "size" or "location" of the component in the paintComponent() method (ie. get rid of the setBounds()). These changes should be done externally as we did by using the setLocation(..) method.
    When you fill the rectangle you should just use getSize().width and getSize().height, instead of your hard coded variables. Then you can dynamically change the size of your component by using the setSize() method.
    The size of the component should not be hard coded. Once you've made the above change you can simply do:
    MyComponent component = new MyComponent();
    component.setSize(25, 50);

  • Doubt about dispose() method of JDialog

    Hi guys,
    Consider the following code:
              MyDialog dialog = new MyDialog(parent);
              dialog.setVisible(true);
                    // may the dialog was disposed before the following line gets executed
              dialog.getVariableValue();
              dialog.dispose();Suppose the MyDialog extends JDialog and have a member variable which can be accessed by getVariableValue() method.
    A dialog appears, enter something which is stored by a member variable of the MyDialog class. Then close the dialog by invoking dispose() method. After the dialog disappears, the next line dialog.getVariableValue() can get the entered value.
    I thought that the dialog will be null after dispose() gets called, but actually not.
    Is the current thread stopped at the line dialog.setVisible(true) and wait for the dialog to be closed?
    Can anyone explain?

    depends if you are to check isDisplayable() after myContainer = nullbut my output would be still
    run:
    100
    LoopsNo1
    There is JFrame
    LoopsNo2
    There is JFrame
    LoopsNo3
    There is JFrame
    LoopsNo4
    There is JFrame
    System Exit
    100
    100
    100
    100
    100
    100
    BUILD SUCCESSFUL (total time: 13 seconds)from code
    import java.awt.Dialog;
    import java.awt.Frame;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JWindow;
    import javax.swing.SwingUtilities;
    public class WindowGCDemo {
        private javax.swing.Timer timer = null;
        private int count = 0;
        public WindowGCDemo() {
            JFrame myFrame = new JFrame();
            for (int i = 0; i < 99; i++) {
                JWindow jWindow = new JWindow(myFrame);
                jWindow.setSize(200, 400);
                jWindow.setVisible(true);
                //jWindow = null;
            start();
            System.out.println(JWindow.getWindows().length); // prints 100
        private void start() {
            timer = new javax.swing.Timer(3000, updateCol());
            timer.start();
        private void startAgain() {
            timer = new javax.swing.Timer(3000, updateColAgain());
            timer.start();
        public Action updateCol() {
            return new AbstractAction("Set Delay") {
                private static final long serialVersionUID = 1L;
                @Override
                public void actionPerformed(ActionEvent e) {
                    timer.stop();
                    Window[] wins = Window.getWindows();
                    for (int i = 0; i < wins.length; i++) {
                        if (wins[i] instanceof JWindow) {
                            wins.setVisible(false);
    wins[i].dispose();
    wins[i] = null;
    System.gc();
    count++;
    startAgain();
    public Action updateColAgain() {
    return new AbstractAction("Set Delay") {
    private static final long serialVersionUID = 1L;
    @Override
    public void actionPerformed(ActionEvent e) {
    System.out.println("LoopsNo" + count);
    Window[] wins = Window.getWindows();
    for (int i = 0; i < wins.length; i++) {
    if (wins[i] instanceof JWindow) {
    } else if (wins[i] instanceof JFrame) {
    System.out.println("There is JFrame");
    } else if (wins[i] instanceof JDialog) {
    System.out.println("There is JFrame");
    } else if (wins[i] instanceof JWindow) {
    System.out.println("There is JWindow");
    wins[i].setVisible(true);
    } else {
    System.out.println("There is something else");
    count++;
    startAgain();
    if (count > 4) {
    timer.stop();
    stop();
    private void stop() {
    System.out.println("--------------------------------------------");
    System.out.println("System Exit");
    System.out.println(JFrame.getWindows().length);
    System.out.println(JDialog.getWindows().length);
    System.out.println(JWindow.getWindows().length);
    System.out.println(Frame.getWindows().length);
    System.out.println(Dialog.getWindows().length);
    System.out.println(Window.getWindows().length);
    System.exit(0);
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    WindowGCDemo windowGCDemo = new WindowGCDemo();
    }Edited by: mKorbel on 18.9.2011 23:30 typos                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Question about synchronizing two methods...

    i have 2 methods:
    writeData() //method 1
    createNewDataFile() //method 2
    the main thread will be using method 1 quite frequently. In method 2, a separate thread will be waking up every 10 minutes or so and doing some maintenance on the file written to in method 1. So, when the thread is in method 2 i need method 1 to standby and wait. I also want the opposite, that when the main thread is in method 2 method 1 will stand by.
    Any help is appreciated!

    799454 wrote:
    So wait,
    i thought synchronized only worked on the actual methods where it is declared:Using the synchronized keyword obtains a lock. Each object has exactly one lock associated with it. Once a thread has obtained an object's lock, no other thread can obtain that lock (and hence cannot enter a sync block on that lock) until the first thread releases it by leaving its sync block or calling wait().
    so, you're saying that if i declare:
    synchronized method 1
    synchronized method 2
    then i have a single object with 2 synchronized methods, so if thread A is in EITHER of those methods, the other method will be locked as well?The method isn't "locked" per se, but yes, 1 object, 2 synced methods, if T1 is in either method, then T2 cannot enter either method.
    I strongly urge you to go through that tutorial and/or a book on Java concurrency, thoroughly.

  • Doubt about  a null value assigned to a String variable

    Hi,
    I have a doubt about a behavior when assigning a null value to a string variable and then seeing the output, the code is the next one:
    public static void main(String[] args) {
            String total = null;
            System.out.println(total);
            total = total+"one";
            System.out.println(total);
    }the doubt comes when i see the output, the output i get is this:
    null
    nulloneA variable with null value means it does not contains a reference to an object in memory, so the question is why the null is printed when i concatenate the total variable which has a null value with the string "one".
    Is the null value converted to string ??
    Please clarify
    Regards and thanks!
    Carlos

    null is a keyword to inform compiler that the reference contain nothingNo. 'null' is not a keyword, it is a literal. Beyond that the compiler doesn't care. It has a runtime value as well.
    total contains null value means it does not have memory,No, it means it refers to nothing, as opposed to referring to an object.
    for representation purpose it contain "null"No. println(String) has special behaviour if the argument is null. This is documented and has already been described above. Your handwaving about 'for representation purpose' is meaningless. The compiler and the JVM don't know the purpose of the code.
    e.g. this keyword shows a hash value instead of memory addressNo it doesn't: it depends entirely on the actual class of the object referred to by 'this', and specifically what its toString() method does.
    similarly "total" maps null as a literal.Completely meaningless. "total" doesn't 'map' anything, it is just a literal. The behaviour you describe is a property of the string concatenation operator, not of string literals.
    I hope you can understand this.Nobody could understand it. It is compete nonsense. The correct answer has already been given. Please read the thread before you contribute.

  • Synchronized method in a java class used by many interfaces

    My interface (idoc to file) is using a java class, which has one method that reads a table from a central database and after doing some calculations updates it.
    (The interface instantiate the class inside a user-defined function and calls the method there.)
    The problem is that if somebody sends 100 idocs at the same time, there can be a “dirty read”, I mean, a read just before other interface updates the table.
    We want the following:
    Interface 1:
    -          Read counter from the table (counter = 5 )
    -          Increment counter (counter = 6)
    -          Update table with that counter (table with counter = 6)
    Interface 2:
    -          Read counter from the table (counter = 6 )
    -          Increment counter (counter = 7)
    -          Update table with that counter (table with counter = 7)
    RESULT: The table has the counter = 7
    But what is happening is the following:
    -          Interface 1 reads (counter = 5)
    -          Interface 2 reads (counter = 5)
    -          Interface 1 increments counter (counter = 6)
    -          Interface 2 increments counter (counter = 6)
    -          Interface 1 updates table (table with counter = 6)
    -          Interface 2 updates table (table with counter = 6)
    RESULT: The table has the counter = 6 (WRONG)
    I made the method synchronized. What I was expecting was that only one interface (i1) could enter the method (read the table and update it) while other interfaces running at the same time would have to wait until i1 finished that method.
    My first test indicates that's not happening. Can anybody help me to find a solution?

    Hi Bhavesh,
    If the QOS is EOIO this means that the integration engine manage the call to the mapping program (and all the other blocks) inside an "internal" synchronized method.
    So this means that in this case you do not need to manage the queued access (synchronization) inside your custom java code because it is already enveloped in a queued block by XI.
    The problem that Jorge had can be easily reproduced using the sample code that follows:
    <b>class Synch Object</b>
    import java.util.Date;
    public class SynchObject {
         String strName;
         public SynchObject(String strName){
              this.strName = strName;
         public synchronized void syncWrite(String strCaller) throws InterruptedException{
              Date now;
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " entering syncWrite of " + strName);
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " syncWrite of " + strName + " called by " + strCaller );
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " leaving syncWrite of " + strName);
              System.out.println("");
              System.out.flush();
    <b>class Caller</b>
    public class Caller implements Runnable {
         String strName;
         SynchObject target;
         int intMax;
         public Caller(String strName, SynchObject target, int intMax) {
              this.strName = strName;
              this.target = target;
              this.intMax = intMax;
         public void run() {
              for(int i=0; i<intMax;i++)
                   try {
                        target.syncWrite(strName);
                   } catch (InterruptedException e) {
                        e.printStackTrace();
    <b>class Workbench</b>
    public class Workbench {
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              SynchObject sObj1 = new SynchObject("syncObj1");
              SynchObject sObj2 = new SynchObject("syncObj2");
              Caller c1 = new Caller("caller1",sObj1,2);
              Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
              Thread ct1 = new Thread(c1);
              Thread ct2 = new Thread(c2);
              ct1.start();
              ct2.start();
    Run the workbench class to see what happen when setting QOS EOIO (the synch object is the same).
    To see instead what happen now (missing synchronization) you have to change in Workbench class the statement
    Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
    with
    Caller c2 = new Caller("caller2",sObj2,2); '[*CHANGE*]
    The reason is that every instance of the mapping program declare a new instance of the "Synchronized object" so the calls are synchronized inside the same mapping program but not between several mapping program.
    Hope this give you a better idea on this problems with java synchronization, but if you have further doubts (I know it's a little bit tricky ) feel free to ask.
    Kind Regards,
    Sergio

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

  • Doubt about Tunning View Objects

    Hi !. I have the following doubt about tunning View Objects:
    If I have the following configuration on a VO:
    All Rows
    In Batches Of: 11
    As Needed
    Access Mode: Scrollable
    Range Size: 10
    Total Records On The Table: More than 100
    What would happen is that while the initial render, the view cache is fetch with 11 rows from the table and the ui table shows 10. In subsequent scroll events, more queries again will be done but not when the user scrolls back. My doubt is this one: Why, while the initial render If I put a breakpoint in this overrided method executeQueryForCollection, the execution reachs there but in subsequent scroll events (forward) the execution doesn't reach there ?. I understand thast this should happen as the required rows are not yet in the cache. I would like to know a way to test this access mode and what method is executed in every roundtrip to the DB. Thankx !.

    I don't think ADF needs to execute the query again - it just needs to fetch the next set of records.
    So if the cursor is already open, no need to issue another query.
    You can use the HTTP Analyzer to watch network traffic
    Monitoring ADF Pages Round-Trips with the HTTP Analyzer
    And you can use the logging features of ADF to see the queries being executed.
    Declarative View Objects (VOs) for better ADF performance

  • Doubt about @SequenceGenerator annotation (sequenceName element)

    Hello, everybody!
    I'm with a doubt about the @SequenceGenerator annotation. What is that sequenceName element? Is that a stored procedure in the database that we have to create or what? If we specify it, what do we have to create in the database? If we don't specify the sequenceName element, will the sequence be generated for us?
    Thank you in advance.
    Marcos

    B.Mansour Nizar wrote:
    no i don't want to remove the @GeneratedValue but instead just bypass it just in that case only to gain peformanceEither you bypass JPA altogether for the task and then manually update the sequances afterwards or, if you are using hibernate, you implement a custom Idgenerator that can use a provided ID.
    The implementation involves extending IdentityGenerator and ovveriding the generate method to return super.generate if the entity Id is null and return the supplied entity's Id otherwise. You then set that generator for that entity.

  • DOUBT ABOUT MASTER DATA

    Hey guys!!!
    I have a doubt about master data, i need to add an atribute to a master data characteristic, do i have to erase the data to do this or can i add the atribute without erase the data?
    Thanks and Regards!!

    >
    Koundinya Karanam wrote:
    > Hi,
    > You should delete the Master data with SID's first before adding the attribute to that characteristic.
    >
    > Regards,
    > KK.
    KK,
    Thats not true.
    You neednot delete master data to add attributes to a characteristic.
    Additionally, you cannot delete (there are methods to delete which are not suggested) master data in normal way, if there is transactional data for that characteristic.
    Luis,
    You should be able to add attribute to a characteristic without deleting master data, but make sure you load data for the same for values to reflect.

  • Doubt about scope of instance variable

    Hi All,
    i have a doubt about scope of instance variable.
    if i declare a instance variable in servlet , i want to know whether it can be shared(means everywhere ) or not.
    thanks in advance
    Gopal

    The servlet container will create one servlet object, and run multiple threads through its service() / doGet() / doPost() methods.
    That means that any instance variables of the servlet are shared between multiple requests, and can cause problems with threads accessing the same variable..
    To make your servlets thread-safe
    1 - have no instance variables - only use local variables in the doGet/doPost method.
    2 - use the session scope for storing variables you need over multiple calls.
    Cheers,
    evnafets

  • Doubt about string.intern()

    Hello
    I have a doubt about string.intern() method.
    The document says
    When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the String.equals(Object) method, then the string from the pool is returned.
    So what is the point of using this intern() method with == or != operators if it aleady calling to equals method internally?
    eg:
    if (studentObject.getName().intern() == "Student Name") {}cannot be better than
    if (studentObject.getName().equals("Student Name")) {}Can someone please explain?

    Easy dude.
    >
    Why do you need to optimize it?>
    Because i want to.
    I would avoid the whole stupid 100 line if-else by doing a Map of type->object and then just clone() the object. But maybe that might not be suitable or "fast enough" for you.I cannot do above because object have it's own behaviors varying at run time
    eg - class One has setOne method and class hundred has setHundred method
    . Even if i use a map and clone it again i have to use above comparison for setting those behaviours.
    Explain your actual problem you're trying to solve, with actual cases. What are these "one" and "Hundred" classes really? Or is your project so top secret that you can't tell us?It is not secret but big. And I need to make the question understandable. If I post the whole code no one will looking at it.
    Now you asking so please have a look.
    still I have cleaned up many.
    My initial question was how to bit speed up the comparison? And can't i use intern() Because here if I got plenty of rectangles(it is the last) performace sucks.
    for (CObject aObject : objList) {
                if (aObject.getType().equals(SConstant.TEMPLATE)) { /* process Template */
                    Template tObj = (Template) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("PAGE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    context.put(retemplateProperties.getProperty("BAND_OBJECT"), dtmBand);
                    tObj.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.LINE)
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Line object = (Line) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("LINE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, object);
                    context.put(retemplateProperties.getProperty("LINE_OBJECT"), object);
                    template.merge(context, writer);
                    object.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.IMAGE) /* process Image */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    REImage imageObject = (REImage) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("IMAGE"));
                    VelocityContext context = new VelocityContext();
                    updateContextWithCheckShifting(context, imageObject);
                    context.put(retemplateProperties.getProperty("IMAGE_OBJECT"), imageObject);
                    mageObject.setTags(writer.toString());
                   else if (aObject.getType().equals(SConstant.RECTANGLE) /* process Rectangle */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Rectangle rectangleObject = (Rectangle) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("RECTANGLE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, rectangleObject);
                    context.put(retemplateProperties.getProperty("RECTANGLE_OBJECT"), rectangleObject);
                    template.merge(context, writer);
                    rectangleObject.setTags(writer.toString());
                }And masijade
    Thank you very much for the better explanation.

Maybe you are looking for

  • Standard report  for production order

    Dear all Is there any standard report with reference to material for all procuction orders ie open,closed etc

  • Recording Video to SD - 4GB Limit?

    I've encountered a bug with the video camera on the Z10.  I'm using what I assume is the latest version of the software that was pushed out recently (10.2.1.2102). I was recording video and after half an hour or so I received an error message stating

  • The same type and red coercion dot

    Hi! A small project is attached to show how red coercion dot appears if you remove"lib type definition.ctl" from library to a virtual folder. It is interesting that this affects only class property nodes. It does not affect class accessors ("setters"

  • How do I close/disable Adobe Update Manager from MenuBar?

    Hello, I would like to remove the Adobe Update Manager from my menu bar for my Mac. It just really annoys me and I really like a clean menu bar. Thanks,

  • Date Converstion Function module

    Hi,              Is there any Function Module to convert Date. I want to convert YYYYMMDD to DD/MM/YYYY. ?? Thnak you hemanth