Static vs SingleTon

I have a page reporting code in the form of jsp tag,which I include in some pages. I capture web page details like persontype,breadcrum details. I pass pageContext as parameter to a class and capture the information.
Is it ok to use Single object or simply make all static method. Inside static method there are object local variables which are accessed. Is it a thread safe or should I synchronize the static method or put syn block around external objects.
Thanks......

Thanks for the reply and I apologize if I wasn't clear. I just want to get details from the request object and then set it into Javascript parameter. So essentially I am just using my classes as Utility to get the details from pageContext object and do some manipulation.
There are no class variables and I am using my classes simply for getting some paramter and adding some to it and set them in Javascript parameters in my JSP page.
Thanks

Similar Messages

  • Static vs Singleton for cache

    Hi!
    I'm developing a web application, where I want to cache some Java objects in a HashMap. The Objects will then be fetched using something like this:
    Cache.getPost(String key);
    But I'm not sure if I can use a static method and a static HashMap for this? Is a Singleton more suited? If so, why?
    Vidar

    Allow me to elaborate...
    Using a static hashmap and a static method, there will >only be one 'instance' of the hashmap, shared between >the different instances of the class, right?Yes, if you choose to instantiate instances of the class that contains the static hashmap. Typically when you have a situation like what you are describing you don't need to create instances of the class containing the map itself - just provide methods to get/put data in and out of the map. Here is a quick example:
    public class Cache {
    private static Map cacheMap = new HashMap();
    public static void set(Object key, Object value) {
    cacheMap.put(key, value);
    public static void get(Object key) {
    cacheMap.get(key);
    The Singleton only has one copy(usually) of the >hashmap as well, because there will only be one >instance of the class itself.That is correct. The only difference from the above example is the fact that you will declare the Map as an instance attribute, and not a static attribute.
    My plan is to fill the cache with objects created with >data from my database at startup, and check the >database every 10 minutes to see if there has been any >changes. If there has, the cache will be updated to >reflect this.Not a problem - the "static" example above will work just fine, as will a Singleton solution. What you have to watch out for is thread concurrency issues. For example, let's say that I go to the cache at the exact same instant that a daemon thread is updating data from the database. You can't guarantee that your cache request will be the old or new value without handling thread locking issues. There is really not enough space here to give this the attention it deserves. I'd recommend that you take a look at the threading forum and see if there are any cache updating examples posted over there...
    Will both a singleton and static solution be capable >of doing this?Yes. Both are capable, and it boils down to a matter of choice more than anything else. The big issue you need to address is how to handle the updating process.
    Jonathan House

  • Static versus singleton

    I have a class which currently has only static methods; no initialisation of the class is needed for it to be used.
    The (static) methods of this class are used constantly.
    Would it be better (in terms of performance, etc.) to use the singleton pattern for this class - i.e. to have one held reference to the class?
    What actually happens when a static method on a class is used - is an "instance" created on the heap, which is then destroyed immediately after use? If this is the case then I'd think the singleton pattern is the best choice, so that the class doesn't get created and destroyed each time.
    Thanks,
    Ed

    I have a class which currently has only static
    methods; no initialisation of the class is needed for
    it to be used.
    The (static) methods of this class are used
    constantly.Looks this object serves as a utility for your application. Am I right ?
    If right, don't go for singleton. Let it be static fully. Let this class not be instatiated. Refer the members of this class by static references directly. Because singleton is used for different circumstances. Usage here would confuse the reader and is also inappropriate.
    Would it be better (in terms of performance, etc.) to
    use the singleton pattern for this class - i.e. to
    have one held reference to the class?Static is known to be a better performer than non-static
    Rajesh

  • Static or singleton?

    What better to use:
    1.
    class MyConfiguration {
      private static String text;
      public static String getText() {
      public static void setText(String text) {
       this.text. = text;
    static void load() {}
    static void save() {}
    }and use like this:
    MyConfiguration.load();
    MyConfiguration.getText();
    MyConfiguration.setText();
    MyConfiguration.save();or
    2.
    class MyConfiguration {
      private static MyConfiguration instance;
      public static MyConfiguration getInstance() {
        if (instance == null) {
          instance = new MyConfiguration();
    private MyConfiguration() {
      private String text;
      public String getText() {
      public  void setText(String text) {
       this.text. = text;
    void load() {}
    void save() {}
    }and use like this:
    MyConfiguration.getInstance().load();
    MyConfiguration.getInstance().getText();
    MyConfiguration.getInstance().setText();
    MyConfiguration.getInstance().save();My question is: What is better to use 1 or 2?

    A concrete reason is unit testing. Let's say you wanted to stub/mock your MyConfiguration class in a test case so it returned a value of your choosing. With option 1, you can't do that - you'd be forced to write a real configuration file and have your MyConfiguration class read it in. With option 2, you could extend MyConfiguration to create TestConfiguration, or better still, use a test library like EasyMock or jMock to do the work for you, leaving you to simply record or specify stubbed/expected values.
    As a wee aside: I tend to avoid singletons because they make unit testing slightly harder than alternatives such as dependency injection. When I do use singletons, for unit testing purposes I normally make the constructor protected rather than private (so the class can be extended) and make the singleton instance field non-final (so it can be 'replaced' by a cheeky setAccessible(true) in my unit tests), e.g.:
    public class TestConfiguration extends Configuration {
      public void pushSingleton() {
        try {
          Field instanceField = MyConfiguration.class.getField("instance");
          instanceField.setAccessible(true);
          instanceField.set(null, this);
        } catch (SecurityException e) {
    // In the test case:
    TestConfiguration config = new TestConfiguration();
    config.setValue("property_x", true);
    config.pushSingleton();

  • Static or singleton for clipboard handling

    Hi Everyone,
    I have the below class with static methods for handling the system clipboard in my small application. I've read that when there is a state maintained I should prefer singleton over static methods. So I guess, I should make this class a singleton because of the Clipboard object in it.
    Could someone maybe explain it a little bit what is behind this advice and why would it be better in this case ? What situation can occur when these static methods are not good but the singleton would be?
    I suppose these methods won't need to be polymorphic in the future, so that's probably not a factor.
    Thanks for any comments in advance,
    lemonboston
    public class ClipboardAction {
         private static Clipboard clipboard;
         static {
              clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         public static String getText() {
              try {
                   Transferable trans = clipboard.getContents(null);
                   return (String) trans.getTransferData(DataFlavor.stringFlavor);
              } catch (UnsupportedFlavorException e) {
                   JOptionPane.showMessageDialog(null,
                             "Not text on Clipboard. Try again.");
                   return "";
              } catch (IOException e) {
                   JOptionPane.showMessageDialog(null,
                                       "Something happened when trying to access clipboard. (IOException)\nTry again.");
                   return "";
         public static void clear(){
              StringSelection data = new StringSelection("");
              clipboard.setContents(data, null);
         public static void setText(String text){
              StringSelection data = new StringSelection(text);
              clipboard.setContents(data, null);
    }

    Thank you guys for the comments. So what is the solution now? :)
    If I understand it correctly there is one vote for static, one for singleton and one for none.
    EJP, do you mean that there is no need to keep a clipboard reference variable? So instead of this in my class:
    private static Clipboard clipboard;
         static {
              clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         }I could use this?:
    private static Clipboard clipboard(){
              return Toolkit.getDefaultToolkit().getSystemClipboard();
         }I don't know what is 'cache' exactly but isn't this system Clipboard (singleton) object there anyway, and I just create a reference for it, which I guess doesn't take too much system resource? Based on this I don't see a big difference in solutions above.
    Or did you mean something else? (probably.. :) )
    Thanks in advance for any further help with this.

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

  • Design Pattern: Is the Universe Object a Singleton or Static or either way.

    Hi All,
    1. I've read this thread: static versus singleton
    http://forum.java.sun.com/thread.jsp?forum=425&thread=401035&tstart=105&trange=15
    2. Now, specifically if you were to model the Universe Object, what would you choose? a Singleton
    or a Static Class or either way depending on your design point of view?
    (either way depending on your design point of view imply there is more than one solution to a problem.)
    Basically, I'm looking for is the justification of one (singleton) or the other (static) or doesn't matter
    in addition to the pure technical pros and cons (or avantage/disavantage) of singleton versus Static (see pt. 1)

    <dubwai>
    What's 'the Universe Object'?
    </dubwai>
    Sorry, for not being clear. My assumption is that every body would undertand the word 'Universe' immediately. So with this clarification. I hope you will have more input. Thanks.
    public class Universe //Singleton
         private static Universe instance = new Universe(); 
         private Universe()
         public static Universe getInstance() 
           return instance;
         public void do() 
    public class Universe  //Static Class like Math class for example
         public static void do() 
         ...all other methods are static
    <os>
    Personally, I'd make the universe a singleton.
    The universe is an 'object', not a class, and if alternate universes are proved to exist you can create new instances,
    and not treat it as a singleton any more, without much rewriting (a static implementation would need a total rewrite).
    </0s>
    1. Keywords: Personally and alternate universes are proved to exist.
    Yes, this is the kind of reasoning I'm looking for. By that I mean when we design a class, our reasonning should not depends
    on the 'pure' technical concepts of what Singleton class or Static class can do but rather depending on the reality
    of the world. And then from that understanding we would choose a Singleton or Static class. This is what I meant by 'Either way, it doesn't matter' which depend on one's view about of existence of the universe whether it's unique or not. In your case (Os), you prefer Singleton because of the possibility of alternate universes.
    2. Now, let's admit, there is only one Universe, would you still prefer Singleton class over Static class? for all the techincal reasons that you said
    "As a singleton,..."
    "It would also probably be useful to treat the universe as a generic Object..."
    OR just because a Singleton would be 'safer' to cover the possibility of design extension in that can cover all cases (alternate as well)

  • Best Practice: passing properties to a Singleton

    Hi,
    I have an object in my app that must only exist once. It is a DatabasConnectionPool. I would like to implement it as a Singleton and access it from anywhere in the app with
    DatabaseConnectionPool dbcp = DatabaseConnectionPool.getInstance();
    But the thing is that I would like to pass it some settings: number of connections to the database, username and password, ...
    If I had a constructor for the class I would pass a Properties object with the constructor containig all the values but how do I do it with a Singleton?
    Right now I have:
    class Singleton {
    private static Properties _appProps = null;
    private static Singleton _instance = null;
    static public void setProperties(Properties appProps) {
    _appProps = appProps;
    static public Singleton getInstance() {
    if (null == _instance) {
    instance = new Singleton(appProps);
    private Singleton(Properties props) {
    So, the Launch code for the application reads the .properties files and calls:
    DatabaseConnectionPool.setProperties(props);
    WebServer.setProperties(props);
    LDAPServer.setProperties(props);
    Thanks a lot for your time guys!
    Rafa

    You don't need synchronization at all if you do it the way a previous post suggested:
    private static Singleton instance = new Singleton();
    public Singleton getInstance(){
        return instance;
    }This is lazy initialization by default because the singleton instance will only be created when the class is loaded into memory. It will be loaded into memory when you first call getInstance() so it's already using lazy initialization.
    The properties question seems to have several options
    1. Use your setProperties method to pass in dynamic properties. This will potentially make your singleton behave differently between uses if you change its properties while it's running.
    2. Hardcode the properties inside the singleton. This doesn't allow dynamic changes.
    3. Your connection pool is probably dishing out Connection objects and creating new ones when needed right? So, put the Connection creation in a different class called ConnectionFactory and pass in the factory to the singleton. This way you can customize the kind of connections to make in the factory without changing the singleton code. All the singleton cares about is saying factory.createConnection() and returning it.

  • Singleton? Don't want to keep reading database

    Hi there,
    I have a java web application, when it starts up I want it to load some information into a singleton so that all requests for this information come from memory not via a database call. The information will change very infrequently but I don't want to hard-code it (I guess I could use a property file). Anyway if I use a singleton will it not be garbage collected as soon as no other objects reference it? If it's garbage collected then the next time some accesses it another database call with be made and I don't want that to happen. I want this object to reside in memory always (it's not large so the hit is not that great). The singleton will basically hold a Vector of "objects" and one of this "objects" attributes is another Vector. To populate it requires 3 trips to the database each time. I would prefer 3 trips up front upon application loading and then no more until a restart occurs. Any suggestions?
    Cheers, Max

    The Singleton pattern is a fairly straightforward pattern. I have used it succesfully several times. Here is an example.
    public class GetInfo {
      private static GetInfo singleton;
      private static Object dataSavedInMemory;
      //Prevent anyone from instantiating this object
      private GetInfo() {
      private static synchronized void initialize() {
        singleton = new GetInfo();
        //One time database processing to save data in memory would go here
        dataSavedInMemory = new String("Hello World");  //just for illustration purposes
      public static GetInfo instance() {
        if (singleton == null)
          initialize();
        return singleton;
      public Object getData() {
        return dataSavedInMemory;
      //Example usage
      public static void main(String[] args) {
        //Get data saved in memory
        Object data = GetInfo.instance().getData();
        System.out.println(data);
        //or
        GetInfo inst = GetInfo.instance();
        Object data2 = inst.getData();
        System.out.println(data2);
    }

  • How to GC a static ref to an object

    If I had an object reference itself, will it ever be GC'ed?
    In the following example, will "a" ever be GC'ed?
    public class RunMe {
      public static void main(String[] args) {
        Test a = Test.getInstance();
        a = null;
    public class Test {
      public static Test getInstance() {
        if(myInstance == null)myInstance = new Test();
        return myInstance;
      private static Test myInstance = null;
    }

    Well dear, you can write some code to see for yourself:
    public class StaticTest{
      public static void main (String args[]){
        StaticClass s = StaticClass.getInstance(); //get instance
        System.out.println(s.getCount());
        s = null; //no references to the object exist
        System.gc(); //should run the collector
        s = StaticClass.getInstance(); //get instance again
        System.out.println(s.getCount());
    public class StaticClass{
      private static StaticClass singleton = new StaticClass();
      private int count;
      public static StaticClass getInstance(){
        singleton.count++; //increment count
        return singleton;
      private StaticClass(){
        count  = 0;
      public int getCount(){
        return count;
    }See dear? Run this and y' should get the output:
    1
    2
    Seems that the static class is only collected when the JVM exits, even though no references to it remain in other classes.
    It's a bit like that rotten pile of unidentifiable substance that always sticks to the bottom of your bin after rubbish day, it only truly lets go when y' hose it off. Horrible.

  • Interesting Qtion: Synchronize a static method

    I know that a non-static method and a block can be synchronized.
    Can anyone tell me as to what it means to synchronize a static method of a class and how/when is it used. I just tried compiling the code and it gives no compiler/syntactical errors.
    it would be helpful if u could take up a simple class example.
    Thanks,
    Novice

    Hi,
    A good example for using synchronized static methods is the singleton pattern. E.g.
    public class Singleton
      private Singleton() {}
      private static Singleton fgUniqueInstance;
      public static synchronized Singleton getInstance()
        if (fgUniqueInstance==null) {
          fgUniqueInstance = new Singleton();
        return fgUniqueInstance;
    }If you won't synchronize this class in a multi-threading environment, it could happen, that more than one instance is created.
    Andre

  • Wrapping entity bean access inside singletons

    Hi all,
    While developing an application based on EJB, i came across a situation which requires some analysis.
    I have a session bean which acts as a session facade - for a set of related entity beans. Since, i wanted to take out all the finders, removes / creator access from the session bean - I created a singleton utility class - which does all the entity bean access. So, the session bean merely calls various methods in the singleton utility class for entity bean access.
    I'am posting it here to get an opinion from others - whether the use of singleton utility class for accessing entity beans - a right approach ?(even though - it does not create any problems during normal testing..)
    Please comment on this approach..
    Thanks in advance,
    Baskar

    Hi,
    The dictionary bean example was quite useful. Thanks.
    But I'am still confused with one thing. i.e.,
    What would be the difference between the below 2 approaches :
    1. Locating & updating / reading from DB tables through CMPs directly from inside the session bean methods. In which case, each client request will have one instance of session bean activated - to service the request. By this, in each of these different session bean instances, the entity bean instances will be created/found/removed/updated.
    2. Using a singleton class/a class containing static methods inside which entity bean instances will be created/found/removed/updated. These static methods/ singleton methods will be used inside each of the session bean instances - in which case, all session bean instances share the code for entity bean access.
    Please give your comments..

  • SINGLETON CLASSES QUESTIONS

    Hello,
    Could someone please explain what the following code does? How does it work? How can I use it in the real program?
    More importantly, if you are kind enough, please give me some examples how to use singleton class? Why do we have to use this class?
    I spent two days on this topic, Singleton, but my mind still goes blank.....
    thank you.
    public class Singleton
    static public Singleton getInstance()
    if(theInstance == null)
    theInstance = new Singleton();
    return theInstance;
    protected Singleton()
    //initializing instance fields
    //instance fields and methods
    private static Singleton theInstance = null;

    Hello,
    Could someone please explain what the following code
    does? The code defines a class called Singleton. :)
    How does it work? The static method "getInstance()" returns an object of type Singleton. Static methods can be called without having an instance of a class, so you can type:
    Singleton.getInstance();
    How can I use it in the
    real program?This class is pretty useless in a real program. The point of this class is to show you how the Singleton design pattern can be implemented in Java. Any useful Singleton object needs to have additional properties and methods. (Oh I know someone will say that you can still use this class for something, but I'm trying to explain something here...)
    More importantly, if you are kind enough, please give
    me some examples how to use singleton class? Sure, here's an example of a singleton: Suppose you want a debugging class that will simply write text to a file. You want to only have one instance of this class (i.e. you don't want to have multiple log files, you want to provide one single interface point for this):
    class LoggerSingleton
      private static final String LOGFILENAME = "log.txt";
      private BufferedWriter write = null;
      private LoggerSingleton instance;
      synchronized static public LoggerSingleton getInstance()
      { if(instance == null)  instance = new LoggerSingleton(LOGFILENAME);
        return instance;
      protected LoggerSingleton(String filename)
        try {
          write = new BufferedWriter(new FileWriter(filename));
          write.write("Log File Opened");
          write.newLine();
          write.flush();
        catch(IOException ioe)
          System.err.println("Error!  LoggerSingleton could not be initialized");
          ioe.printStackTrace(System.err);
          System.exit(1);
      public log(String text)
        write.write(text);
        write.newLine();
        write.flush();
    }This class will make sure you only have one log file and ensures that all classes are using it:
    class FirstClass {
      SecondClass second = new SecondClass();
      public FirstClass() {
        LoggerSingleton.getInstance().log("Inside FirstClass' constructor");
      public void func1() {
        LoggerSingleton.getInstance().log("Inside FirstClass.func1()");
    class SecondClass {
      public SecondClass() {
        LoggerSingleton.getInstance().log("Inside SecondClass' constructor");
    Why do we have to use this class?You don't have to use this class, but it is one technique to ensure that multiple instances of an object are not instantiated. It is also a technique to ensure that there is only one interface point across the application (you can also use a Singleton object to implement the Bridge and Factory design patterns). The Singleton technique is achieved by making the constructor protected, which means that only methods inside the class (and package) can construct instances of Singleton. The only time an instance of Singleton is constructed is the first time that getInstance() is called.
    I spent two days on this topic, Singleton, but my mind
    still goes blank.....
    Still blank?

  • Static method vs synchronisation

    Hi,
    A fundamental query.
    If i am declaring a method as static, can i also declare it as sunchronized? i.e. can i have something like
    public static synchronized sss(){
    xxx
    If a method is static, there is only one instance in the memory. Correspondingly, only one client can execute it at a time. in which case it is automatically synchronized.
    Pl correct my reasoning.
    When do we have the requirement of having a static method, or probably a singleton??
    Thanks,
    Prashant Gupta

    Hi,
    A fundamental query.
    If i am declaring a method as static, can i also declare it as sunchronized? i.e. can
    i have something like
    public static synchronized sss(){
    xxx
    }?Yes, static methods can be synchronized which means that when any thread is running within a synchronized static method of class C, no other thread may enter a static synchronized method of that class. In other words, the monitor acquired by a static synchronized method is the Class itself while the monitor acquired by a non-static synchronized method is the object refered to by 'this'.
    If a method is static, there is only one instance in the memory. Correspondingly,
    only one client can execute it at a time. in which case it is automatically synchronized.There is (in most circumstances) a single copy of the definition (bytecodes representing all methods - static or not - and static fields) of of a class. However, any number of threads may be executing within any section of code unles that code is guarded by a synchronized block or within a synchronized method. In that case, no two threads can enter (well, actually be runnable within - Object.wait() has special implications) a synchronized block monitored by the same object.
    When do we have the requirement of having a static method, or
    probably a singleton??Not sure what you are asking here. You define static methods when there is behavior you want to implement that does not need to have access to instance (non-static) fields or methods and which would never need to be overridden (for purposes of polymorphism) by derived classes.
    Wen needing a singleton, you have a choice of defining a "true singleton" (i.e. a class with a private constructor, some sort of static getInstance() method, with the bulk of its methods anf fields are non-static) or defining a class whose methods are all static and whose fields are also all static. Singletons. Use the one that fits you needs the best.
    Chuck

  • Unit Testing in DAC

    Hi,
    I am facing a problem in unit testing in DAC. I am able to run full loads and incremental but i am unable to do unit testing in DAC. It shows an error that my Integration Services are not up when i run an individual task . Are there any setups for unit testing in DAC. I had followed http://docs.oracle.com/cd/E15586_01/fusionapps.1111/e14849/dacquickstart.htm#BABCIIIH topic : To unit test an execution plan task. If any one would help me in running a unit test that would be a great help.
    Thanks,
    Ram

    I'm struggling with the idea of testing View/Controller classes which depend on "container things" like bindings. Since there are many ways to interact with the 'container things' I guess it depends on exactly how you're using those bindings in your View/Controller classes. I've had success using Mockito along with my own fixture classes that do things like set up a mock ADFContext and RequestContext. Within my test setUp and tearDown, I set up and tear down these fixture classes, which results in a safe, mocked-out environment in which the test can execute. It's often tricky because many of the these objects are static and singleton-like, but so far I've always found a back door by which to inject a mock object. We also have our own utility classes that look-up 'container things', so we of course make sure we have a way to provide mock 'container things' through those utility classes.
    If you haven't come across the concept of 'mock objects' before, then it may be best to do a bit of background reading first:
    [http://www.mockobjects.com/2009/09/brief-history-of-mock-objects.html]
    [http://en.wikipedia.org/wiki/Mock_object]
    There are many mocking libraries about (EasyMock, jMock, rMock) but IMO Mockito is the one to choose right now.
    Of course, the alternative is to apply some [Inversion of Control|http://martinfowler.com/articles/injection.html] and make sure that the code you right is always ignorant of exactly where the 'container things' have come from. This makes mocking much easier, but I've not yet investigated use of a D.I. container (e.g. Spring) along with ADF - I suspect your options in 10g would be limited.

Maybe you are looking for

  • Is there a known problem with Nik Software Plugins and PSE10

    I replaced my PC with a new 64-bit Windows 7 workstation. Have used PSE10 for a while for my cataloging and editing and I did 'trial' individual Nik Software plugins on my old Vista PC for a while. I decided to purchase the Nik Software collection an

  • FCP Real Time Playback

    I want to do real time playback of a FCP project from my MacBook Pro, and it appears my new Matrox MX02 Mini box will allow an HDMI output of my 720p60 project from the MacBook Pro. Pretty cool. What are your best suggestions for encoding a reliable

  • Space before

    Hi, I've got this dumb thing where the text I imported from Word has an extra space after/before each paragraph that I don't want. I tried both find/replacing ^p^p with ^p in the text section, and find/replacing ~b~b+ with \r in the GREP section, and

  • Im installing photoshop on my computer but the update is stuck at 81%

    yes just like the heading states its been stuck on 81% since last night.

  • Date Navigator

    HI Experts i'm using date navigator which contains 3 months ...and select  type is Range... and i'm having two input fields ....  that is Starting Date and End Date what i need is if i select range of date that ex jan  4 , to   ......jan 23 starting