Static class and clustering

          I have a static class that I use to cache some values during a batch process. The
          batch process uses a JMS queue to parcel our identical units of work to MDBs.
          I want this to scale using a cluster with the same MDBs on multiple machines.
          Everything works fine except that I can't figure out how to tell my cache to clear
          itself out on every node between batch runs. Is there a pattern or solution to
          this problem?
          What I've tried is to create a stateless session bean method that clears my cache.
          At the begining of my batch job, (which is a stateless session bean call) I call
          this method on each server in the cluster by getting the remote interface for
          the stateless bean via the different URLs of the servers. However, the session
          bean method always executes on the one server where I make the call. It's as if
          WebLogic gives me back a local interface instead of the remote interface that
          I asked for.
          Any ideas would be appreciated.
          Colin
          

... static class and static method.I have never heard of a thing called "static class". Perhaps you mean a class with only static members?
My design approach (which is bound to needs of the moment and seldom to library-development or future re-use, since both is harder than most developers realize) is to develop straight without caring too much about static or not. When a method is done, debugged and works well, it happens that other objects access this method as well.
It may happen that I just want to use this single method and almost nothing else of the object. If that is the case, I can start looking if it's a Good Thing(tm) to make the method static, so no object creation is needed just for the one method. Sometimes it can be done, sometimes not.
But that's just me and you'll find quite a lot of coders that'll advice you to decide what's static and what not before you start coding. And that's as good an advice as most others you can get.
In the end it's your decision, so start fiddling around and see what fits best for you.
-T-

Similar Messages

  • SQL, static classes and sessionBeans

    Hi,
    my JSF-project has one static class where it handle all sql-queries and I asked me if that is the "best" solution.
    I.e. a User-Sessionbean call that static class to save his data into the user-sql-table. I asked myself, if it might not better to delete this static class and let the user-sessionbean save his data itself.
    If my webserver has 100 usersessions and 50 users save their data at same time, does the "static-sql-save-version" has only one sql-connection and 49 user have to wait in a queue? And with the "every-usersession-has-his-own-sql-save-method" I have got 50 DB connection at the same time?
    I hope you could help me :)
    Alex

    you will gain some bytes by merging all the static classes in one.
    you can create a ManagerTool.java class and write inside all the static methods ...

  • Static classes and variables

    Hello,
    I put all of my constants in an *{color:#3366ff}interface{color}* called Constants.java (I only put constants in this file) and when obfuscated the Constants.class file is removed from .jar and constants are inlined into classes this is Great! However, do I gain anything by placing all of my static methods into one class? Currently, there are all over the place and also I have classes that are already static like HttpMgr.java/ErrorMgr.java/InfoMgr.java I am thinking about merging these classes together with all static methods defined within the project. Do I gain or loss anything by doing this?
    Thanks!

    you will gain some bytes by merging all the static classes in one.
    you can create a ManagerTool.java class and write inside all the static methods ...

  • "Static" class and application server

    Hi, i have a little problem. I need to load a "static" class of a web application, deployed on Bea WebLogic 7 (or Tomcat), when the application server is starting.
    Is it possible ? If yes, how can i do ?
    Thanks

    Yes, It's call from a servlet and the servlet is loaded on start up.
    But I have resolved my problem this morning, however thanks for help. :)
    Claudio

  • Difference between a static class and singleton

    What is the difference between a static object and a singleton ?
    for example:
    1 )
    public class MyObject {
    static MyObject singleton ;
    public static MyObject getInstance() {
    if (singleton ==null) singleton = new MyObject ();
    return singleton;
    private MyObject () {
    supe();
    public void myMethod() {
    2 )
    public class MyObject {
    private MyObject () {
    supe();
    public static void myMethod() {
    If I need to call the myMethod() , witch of this solution is better ?
    // case 1
    MyObject.getInstance().myMethod()
    // case 2
    MyObject.myMethod()
    .....

    This has been discussed a lot here.
    Use the forum's search feature, or, since it's not necessarily reliable, use google.
    For many intents and purposes, they're equivalent.
    However, with a singleton you can implement an interface, and get polymorphic behavior. You can't do with with a class full of static methods (which, by the way, is NOT a static class).

  • Difference between static class and singleton?

    Hi I wonder what could be the difference between static methods and singleton?
    In singleton at any point of time there will be only one object existing in the JVM. We create singleton to avoid multiple object creation for that class.
    If I make all the methods in the class as static also it does the same job. The memory will be allocated once. Even there wont be any object in this case, so time required for object creation also can be saved. looks like more efficient but still why need singleton?
    This question is also posted in java programming forum. The thread is as follows:-
    [Click on this to visit that thread |http://forum.java.sun.com/thread.jspa?threadID=5278517&tstart=0]
    Edited by: murrayb9654 on Mar 25, 2008 8:20 AM

    yawmark wrote:
    Static class is a realization of singleton pattern.Not in any conventional sense.
    ~Especially since a static class is completely different from a class with all static methods.

  • Singleton pattern class and static class

    Hi,
    what is difference between the singleton pattern class and static class ?
    in singleton pattern, we declare a static member[which hold one value at a time] ,static method[ which return static member value] and a private constructor[not allow to direct instantiation]. My words are -- as a singleton pattern we implement static class .
    so can we say a singleton pattern is static class it means both are same or is any difference between these two ??

    malcolmmc wrote:
    On several occasions I've had to convert a static (never instanceated) class to a singleton type, for example because I realise I need an instance per thread, or I decide to make a program more modular, with more than one configuration.
    I've never done the opposite.
    So generally I favour the singleton if there any "state" involved, because it's more flexible in unanticipated directions. It also gives extra flexibility when building tests, especially if you program to an interface.Total agreement; if anything it is dead hard to override static method logic with mock code in unit tests (I had to do it by keeping the static methods in place but making them internally use a singleton instance of itself of which the instance variable could be overwritten with a mock implementation for unit testing purposes...).
    'Static classes' and/or methods are great for very simple util functions, but I wouldn't use them for anything other than that.

  • Static class

    Hello
    at the start of my programme I would like to store some valuse (the values are trhe user rights that will be read from the data base) these values will never change during the execution of the programme.
    so I was told that the best is to create a static class ...
    can any one post an example of static class and how to store the values inside
    and how to read it back
    or just any link that speak about this
    thank you in advance.

    yeah i understand the ?:;
    my question was on the form of the newthe code checks to see if an instance of Example already exists, and if it does, it returns that. if not, it creates a new one first. theoretically, only one instance will ever exist, but in practice, this variant of the pattern isn't thread-safe. simplest singleton:
    public class MySingleton {
      private static MySingleton INSTANCE = new MySingleton();
      private MySingleton() {}
      public static MySingleton getInstance() {
        return INSTANCE;
    }still lazily-loaded, despite what people might tell you, since the class itself is only loaded when you first need it

  • What is static class ?

    I know about static function.
    What is static class?
    What is the use of static class?
    how can i use static class.?
    Give me a  static class example?

    Static class and singleton are similar but they are not the same. A singleton is instantiated, and you have a reference to it - just one single reference no matter how many times you instantiate it. Singletons are good for data storage, config settings, loggers things that you may need all around your application, but you always want the same one.
    A static class is not instantiated - an example of this is Flash's Math class. You can just do Math.sin() and get a result, you don't instantiate it in order to use it. Static classes are good for utility classes... essentially they are simply a namespace for a group of methods.
    Oh, and you said you know about static function - what is static class - a static class then is just one that contains only static functions/methods.

  • Do Static Classes exist?

    Does Java allow the creation of static classes, and if so does that mean an instance of the class cannot be created? I know that a class can have static methods that only access static instance variables, but I don't know if that means that the class itself is static. I ask because I realized that you can't declare a static class like "public static class A {...}"

    @OP. An inner class can be declared to be static,but
    top level classes can't be static.
    But that doesn't mean the static inner class
    can't be instantiated (which seems to be what the OP
    is thinking of).That was an answer to the topic - "Do static classes exist?", and the question does also say:
    "Does Java allow the creation of static classes, and if so does that mean an instance of the class cannot be created?"
    So I thought that the OP also wanted to know if static classes existed.
    Kaj

  • About static class

    Dose Java has Static class?
    What is diff between static class and a final class which all method are static in java?

    Dose Java has Static class?yes, but only if the class is an inner class
    a static inner class does not have a reference to its enclosing class - because of this, a static inner class cannot use this to access any instance variable of the enclosing class
    however, a static inner may access all static variables of the enclosing class
    What is diff between static class and a final class
    which all method are static in java?a static inner class is linke any other class in java
    a final class with static methods is like the java.lang.Math class - you cnnot subclass it and do normally not instantiate it
    hope that helps
    Harry

  • Nested Classes and Static Methods

    I was perusing the Java Tutorials on Nested Classes and I came across this...
    [http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
    I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
    Static Nested Classes
    As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
    Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Private inner class and static private inner

    Hi,
    I understand the concept and usage of inner classes in general.
    When should we go for a private inner class and when for a static private inner class? I tried searching but it wasn't of much help.
    Basically I need to design a caching solution in which I need to timestamp the data object. After timestamping, data will be stored in a HashMap or some other collection. I'm planning to use a wrapper class (which is inner and private) which holds the data object and timestamp. I can make the program work by using either normal inner class or static inner class, however would like to know which is better in such case. Also If I can get some general guidelines as to when to use a staic inner class and when to use a normal inner class, it would help me.
    Thanks in advance.

    user1995721 wrote:
    When should we go for a private inner class and when for a static private inner class?
    I can make the program work by using either normal inner class or static inner class, however would like to know which is better
    If I can get some general guidelines as to when to use a static inner class and when to use a normal inner class, it would help me.Making the inner class static is helpful in that it limits visibility.
    If the inner class needs to access non-static fields or methods from the containing class instance
    the inner class has to be non-static.

  • How do i create a static function in a class and implement ActionListener?

    i am trying to create a pop up dialog box in a seperate class.
    and i want to make the Function static, so that i only need to access it with the class name.
    But how do i have a ActionListener ?
    everything in a static function is static rite?

    import java.awt.*;
    import java.awt.event.*;
    public class StaticFunction
        Dialog dialog;
        private Panel getUIPanel()
            Button button = new Button("show dialog");
            button.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    if(dialog == null)
                        dialog = OutsideUtility.showDialog("hello world");
                    else if(!dialog.isVisible())
                        dialog.setVisible(true);
                    else if(dialog.isVisible())
                        dialog.dispose();
                        dialog = null;
            Panel panel = new Panel();
            panel.add(button);
            return panel;
        private WindowListener closer = new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
        public static void main(String[] args)
            StaticFunction sf = new StaticFunction();
            Frame f = new Frame();
            f.addWindowListener(sf.closer);
            f.add(sf.getUIPanel());
            f.setSize(200,100);
            f.setLocation(200,200);
            f.setVisible(true);
    class OutsideUtility
        public static Dialog showDialog(String msg)
            Button button = new Button("top button");
            button.setActionCommand(msg);
            button.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    Button button = (Button)e.getSource();
                    System.out.println(button.getActionCommand() +
                                       " from anonymous inner listener");
            button.addActionListener(new ButtonListener());
            Button anotherButton = new Button("bottom button");
            anotherButton.setActionCommand("another button");
            anotherButton.addActionListener(localListener);
            Panel north = new Panel();
            north.add(button);
            Panel south = new Panel();
            south.add(anotherButton);
            Dialog dialog = new Dialog(new Frame());
            dialog.addWindowListener(closer);
            dialog.add(north, "North");
            dialog.add(new Label(msg, Label.CENTER));
            dialog.add(south, "South");
            dialog.setSize(200,200);
            dialog.setLocation(425,200);
            dialog.setVisible(true);
            return dialog;
        private static WindowListener closer = new WindowAdapter()
            public void windowClosing(WindowEvent e)
                Dialog dialog = (Dialog)e.getSource();
                dialog.dispose();
        private static ActionListener localListener = new ActionListener()
            public void actionPerformed(ActionEvent e)
                Button button = (Button)e.getSource();
                System.out.println(button.getActionCommand() +
                                   " from localListener");
        private static class ButtonListener implements ActionListener
            public void actionPerformed(ActionEvent e)
                Button button = (Button)e.getSource();
                String ac = button.getActionCommand();
                System.out.println(ac + " from ButtonListener");
    }

  • Static Class JMS Listener

    I am designing an EJB component (MessageDrivenBean) that requires
    dynamic ("hot") configuration changes. As such, the bean must be
    notified somehow of configuration changes in the DB (rather than have
    to poll the DB for changes at every method call).
    I'm thinking of implementing this functionality using a static class
    instance (singleton) that is shared between the multiple instances of
    the bean. This static instance would listen on a JMS topic for
    configuration change events and update its internal cache accordingly
    (by getting the configuration information from the DB). The beans
    would then access this in-memory static instance everytime they need
    configuration info instead of polling the database. By using the JMS
    topic, I guarantee that clustered instances of Weblogic will all be
    notified of the database changes (each instance would have its own
    "cache" singleton).
    I'm pretty sure all of this will work, but I'm equally sure that I'm
    violating some EJB rules. Singletons and JMS listeners are generally
    discouraged. Are there any alternatives to this design?

    Hi Joost,
    This all seems to be pretty complicated. Not to mention that you can not
    guarantee that members of a cluster will be notified simultaneously.
    Why don't you want using the database?
    "Joost Ouwerkerk" <[email protected]> wrote in message
    news:[email protected]..
    I am designing an EJB component (MessageDrivenBean) that requires
    dynamic ("hot") configuration changes. As such, the bean must be
    notified somehow of configuration changes in the DB (rather than have
    to poll the DB for changes at every method call).
    I'm thinking of implementing this functionality using a static class
    instance (singleton) that is shared between the multiple instances of
    the bean. This static instance would listen on a JMS topic for
    configuration change events and update its internal cache accordingly
    (by getting the configuration information from the DB). The beans
    would then access this in-memory static instance everytime they need
    configuration info instead of polling the database. By using the JMS
    topic, I guarantee that clustered instances of Weblogic will all be
    notified of the database changes (each instance would have its own
    "cache" singleton).
    I'm pretty sure all of this will work, but I'm equally sure that I'm
    violating some EJB rules. Singletons and JMS listeners are generally
    discouraged. Are there any alternatives to this design?Regards,
    Slava Imeshev

Maybe you are looking for

  • Adobe Acrobat X Pro Mac download

    Where on adobe's website can i download adobe acrobat X Pro for Mac?

  • Installing windows from recovery dvd

    Hi. When i first purchsed my Mac, i inserted the Windows recorvery dvd to install Boot Camp. It completly wiped the Mac OS and installed Windows. i then had to format the hard drive and reinstall Mac OS. Since then i have tried to look into it but i

  • CPROJECTS - How does the calculation take place ?

    Hi, I am wokring in cprojects. I have done the following entries <u><b>cost revenue rate - defined</b></u> amount costs - 50 US dollars /Hrs amount revenue 10 US dollars/Hrs different revenue - 1.0 US dollars / Hrs. <b><u>resource assigned and staffe

  • Sharing ical with pc user

    I actually have a MacBook (OS X 10.7 something) and I love my iCal. I'd like to share my work schedule with my Mom but her PC is not reading the iCloud share link at all. Can't copy paste it, can't link, can't nothing. She does not have Outlook. Can

  • Variables to a BI Query from input form and chart?

    Hi, I have a query (QUERY A) to which I connected an input form to define the variables. The output is a chart which tells us a status overview. Now I want to use the input form as well for entering the variables for QUERY B. This is no problem as th