> i prefer thread-safe implementations > Sometimes we need to have only one instance of our class for example a single DB connection shared by multiple objects as creating a separate DB connection for every object may be costly.
I ran a raw (without connection pooling) DB Connection test with the following results (see below); query time 8 ms and DB connection time is 324. So I am using thread safe connection pooling strategies found here. https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html Asynchronous Connection Retrieval https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html *connecting to Postgres Database .....John Casserole Y 2012-04-11Sandy Key Lime Tarts N 2012-04-14Tom BBQ Y 2012-04-18Tina Salad Y 2012-04-18 DB Connectime miiliseconds 324 query time taken miiliseconds 8Connection + query time miiliseconds 335* *import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class QueryTable { public static void main(String[] args) { long Start = 0; long queryTime = 0; long connTime = 0; try { System.out.println("connecting to Postgres Database ....."); Connection conn = null; Statement stmt = null; Start = System.currentTimeMillis(); Class.forName("org.postgresql.Driver"); conn = DriverManager .getConnection("jdbc:postgresql://localhost:5432/events", "postgres", "sunrise"); connTime = System.currentTimeMillis(); stmt = conn.createStatement(); queryTime = System.currentTimeMillis(); ResultSet rs=stmt.executeQuery("select * from potluck"); while(rs.next()) System.out.println(rs.getString("name")+" "+ rs.getString("food")+" "+ rs.getString("confirmed")+" "+ rs.getString("signup_date")); conn.close(); } catch (Exception e){ System.out.println(e);} long End = System.currentTimeMillis(); System.out.println(" DB Connectime miiliseconds " + (connTime - Start) ); System.out.println(" query time taken miiliseconds " + (End - queryTime) ); System.out.println("Connection + query time miiliseconds " + (End - Start) ); }}* On Fri, 13 Dec 2019 at 01:33, Martin Gainty <mgai...@hotmail.com> wrote: > Singleton: > i prefer thread-safe implementations and generally eschew singletons > (unless extreme political pressure dictates otherwise) > https://www.geeksforgeeks.org/singleton-design-pattern/ > [https://www.geeksforgeeks.org/wp-content/uploads/gfg_200X200.png]< > https://www.geeksforgeeks.org/singleton-design-pattern/> > Singleton Design Pattern | Implementation - GeeksforGeeks< > https://www.geeksforgeeks.org/singleton-design-pattern/> > The singleton pattern is one of the simplest design patterns. Sometimes we > need to have only one instance of our class for example a single DB > connection shared by multiple objects as creating a separate DB connection > for every object may be costly. Similarly, there can be a single > configuration ... > www.geeksforgeeks.org > > Design Patterns: > have a look at this discussion from stackoverflow on Visitor Pattern vs > Command Pattern for lambda expresssions > https://stackoverflow.com/questions/2186931/java-pass-method-as-parameter > [ > https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-i...@2.png?v=73d79a89bded > ]< > https://stackoverflow.com/questions/2186931/java-pass-method-as-parameter> > interface - Java Pass Method as Parameter - Stack Overflow< > https://stackoverflow.com/questions/2186931/java-pass-method-as-parameter> > In Java 8, you can now pass a method more easily using Lambda Expressions > and Method References. First, some background: a functional interface is an > interface that has one and only one abstract method, although it can > contain any number of default methods (new in Java 8) and static methods. A > lambda expression can quickly implement the abstract method, without all > the unnecessary syntax ... > stackoverflow.com > although this discussion is more specific on when to implement Visitor > Pattern vs when to use Command Pattern > > https://stackoverflow.com/questions/2857880/command-pattern-vs-visitor-pattern > [ > https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-i...@2.png?v=73d79a89bded > ]< > https://stackoverflow.com/questions/2857880/command-pattern-vs-visitor-pattern > > > Command Pattern vs. Visitor Pattern - Stack Overflow< > https://stackoverflow.com/questions/2857880/command-pattern-vs-visitor-pattern > > > Each pattern has it's own pros, cons and use cases. You can use Command > pattern to . Decouple the invoker & receiver of command . Implement > callback mechanism. Implement undo and redo functionality. Maintain a > history of commands. Use Visitor pattern in below scenarios:. Similar > operations have to be performed on objects of different types grouped in a > structure ; You need to execute many ... > stackoverflow.com > > ?am interested to know which topic prompts your question? > > /br/ > Martin > ________________________________ > From: Lukasz Lenart <lukaszlen...@apache.org> > Sent: Thursday, December 12, 2019 1:56 AM > To: Struts Users Mailing List <user@struts.apache.org> > Subject: Re: Java Singleton , Framework Design Patterns > > czw., 12 gru 2019 o 06:13 Zahid Rahman <zahidr1...@gmail.com> napisał(a): > > So my point is I have not been able to find accurate information , if > some > > one could furnish me a Java language specification or recommend a book > > which accurately describes these I would be grateful. > > Start with Gang of Four > http://www.blackwasp.co.uk/gofpatterns.aspx > > > Regards > -- > Łukasz > + 48 606 323 122 http://www.lenart.org.pl/ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >