All 36 entries tagged Java

View all 241 entries tagged Java on Warwick Blogs | View entries tagged Java at Technorati | There are no images tagged Java on this blog

April 12, 2013

Chrome Java plugin

On my ubuntu box, there are two versions of JDK installed: OpenJDK and Sun JDK.

The latest version OpenJDK I can get now is openjdk-7-jdk.


root> java -version
java version "1.7.0_15" 
OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

With OpenJDK, you can install package “icedtea-7-plugin” to install the java plugin for Chrome. You can go “http://www.java.com/” and click “Do I have Java” to verify the Java version. The verification page display a blank page even after I accepted the security warning. However, I can succesfully verify in http://javatester.org/enabled.html
Somehow, the IcedTea crashed often.

I downloaded the binary version of Sun JDK and installed the software by unzip the binaries:


root>  java -version
java version "1.7.0_17" 
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

To make Chrome use the jre plugins:


cd ~/.mozilla/plugins
 ln -s /apps/jdk1.7.0_17/jre/lib/amd64/libnpjp2.so

Go “http://www.java.com/” and click “Do I have Java” to verify the java successfully.

Type “chrome://plugins” in the address bar, you can see both “IcedTea-Web Plugin” and “Java™ – Version: 1.7.0_17” are enabled. The latter takes precedence.

You can also use http://www.java.com/en/download/testjava.jsp to test the Java plugin.

In the end, I chose to use OpenJDK + IcedTea. Don’t want to manually download and install Sun JDK every time I need to upgrade.


March 08, 2012

CountDownLatch

    public static long time(Executor executor, int concurrency,  final Runnable action) throws InterruptedException {

        final CountDownLatch ready = new CountDownLatch(concurrency);
        final CountDownLatch start = new CountDownLatch(1);
        final CountDownLatch done = new CountDownLatch(concurrency);

        for (int i = 0; i < concurrency; i++) {

            final int j = i;
            executor.execute(new Runnable() {
                public void run() {
                    System.out.println(" ready " + j + " : countDown " + System.nanoTime());
                    ready.countDown(); // Tell timer we're ready
                    try {
                  //      Thread.sleep(1000);
                        System.out.println(" start " + j + " : await " + System.nanoTime());
                        start.await(); // Wait till peers are ready
                        System.out.println(" action " + j + " : run " +  System.nanoTime());
                        action.run();
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    } finally {
                        System.out.println(" Down " + j + " : countDown " +  System.nanoTime());
                        done.countDown();  // Tell timer we're done
                    }
                }
            });
        }

        System.out.println("Ready " +  System.nanoTime());
        ready.await();     // Wait for all workers to be ready
        long startNanos = System.nanoTime();

        System.out.println("Start " +  System.nanoTime());
        start.countDown(); // And they're off!

        System.out.println("Done await " +  System.nanoTime());
        done.await();      // Wait for all workers to finish
        return System.nanoTime() - startNanos;
    }

    public static void main(String[] args) throws InterruptedException {
        time (Executors.newFixedThreadPool(3),3, new Runnable() {

            public void run() {
                System.out.println(" my name: " + Thread.currentThread().getName() + " " + System.nanoTime());
            }
        });
    }

Every thread calls ready.countDown() then wait at start.await().
The main thread will run start.countDown() after ready.await unblocked after all thread called ready.countDown().

If you uncomment the “Thread.sleep()”, the main thread will fire off start.countDown() without care about the status of thread.

The output of System.out.println() in multi-threads does not necessarily appear (in eclipse console) as the same order as they are executed. Append System.nanoTime() in the printed message can confirm that.


December 14, 2008

Checklist before release

Before every release, check the following list:

Documentation finished?
Checked out all CVS code?
Any other changes besides Java code: js, css, configure files (system properties or conf)

Check periodically:
Does functional test need update?


August 14, 2008

Effective Java note

Interface : java.util.Comparator : impose total ordering (more restriction)
Interface: java.lang.Comparable: compareTo method is referred to as its natural comparison method

You must override hashCode in every class that overrides equals
long -> (int)(f^(f>>> 32))
float -> Float.floatToIntBits(f)
double -> Double.doubleToLongBits(f) -> then long to int

P190: Prefer two-element enum types to boolean parameters


July 11, 2007

JVM language property

Use -Duser.language=en to set the lanaugae enviroment in Java application.


November 22, 2006

ORM tools

Writing about web page /java/entry/java_connection_pool/

Writing about an entry you don't have permission to view

Object Relational Mapping (ORM) Tools provide a slick way of persisting objects (data) into database. It has a great impact on Java applications. It reduces the need for developers to write native SQL. The developers can easily let the tools generated complicated SQL. To achieve there program efficiency, developer tend to join several objects, without realizing it will generated a huge SQL require multiple table joins. For DBAs, it means they need to improve performance tuning skills. Oracle optimizer might choose inferior execution plan for a big query.

As a DBA, aware of the following point:

  • Using native SQL in corner cases 90/10. ORM tools is good for manipulate data. For batch loading, updating, deleting, it is far better to use native SQL. For instance, to display all information of several parents and their children, a Java application is likely to loop over every parent to get his children. This way will generate a lot of hit to database. With native SQL, you can easily get this information in one single SQL.
    Some tools provide semi-native portable SQL, for instance, hibernate has HQL, EJB has EJB-QL, you might encourage developer to use them as well.
  • Use lazy loading to avoid generated tons of SQL. Suppose a parent has many children, every child has its own children. If you just want to get information fom a child, with eager loading, this child will automatically load its children. This can leads to generate several queries.
  • break down one complicated big SQL into two or more SQLs.

SQL*Net more data from client

A while ago, OEM report some alert messages to us:

Wait class "Network" was consuming significant database time.  
Wait event "SQL*Net more data from client" in wait class "Network" 
     was consuming significant database time. 

We also see a 30ms slower to render our web pages.

According to Oracle doc,

SQL*Net more data from client
The server is performing another send to the client. The previous operation was also a send to the client.

It is not of much help.

The OEM gives a more clear indication:

Investigate the cause for high “SQL*Net more data from client” waits in Module “JDBC Thin Client”.

It is telling us that something is wrong with the JDBC drivers.

Chris May find a good article here

The cause of this event was a sequence of parse calls that passed excessively long SQL text strings through SQL*Net from the client to the server (instead of using stored procedure calls to accomplish the same thing). The long SQL text strings wouldn’t fit into a single SQL*Net packet, so the Oracle kernel spent a considerable amount of time awaiting second and subsequent SQL*Net packets during parse calls.

Hibernate, the ORM tools used by our application, generates long SQLs. Instead of select * from table, it use select col_1, col_2 from table.

After upgrading to latest JDBC driver, the problem fixed.
fixsqlnet

November 21, 2006

Common features of Java Applications

Agenda

  • Database features
  • Share knowledge
  • Using Java to monitor database

Database Features

Firstly I want to outline some common features of Java web application. These features will influence how a DBA manage his Oracle databases.

First one is a lot of Java applications only use basic Oracle developing functions. All the business logics reside in the middle tier.

Second one is most Java applications use connection pool to cache the connection to databases. Those connections often cross the network.

Third one is that with the popularity of the object-relation-mapping (ORM) tools, Java applications are able to generate SQL, which can be either good news or bad news for DBAs.

Last one is that since it is a n-tier application and any part of this link can be a bottleneck, can be a problem.

Install what you need only

Nowadays, Java developer community is talking about vendor independent. They want their Java applications independent of hardwares, operation systems, databases and even Java application servers. So a Java application wont use such Oracle features like store procedures, triggers , jobs, etc. They only use tables, views, sequences.
This is good for DBA. Most of Oracle recommended components like Java Virtual Machine (JVM), Text, XML wont be used at all. You should choose not to use them when creating the database. This will make the database small and easy to maintain , to upgrade.
I once upgraded two database from 9i to 10g. One has JVM installed and one does not. The one with JVM took more than 2 times longer than the one without.

Consider logical standby database for high availability

Logical standby database is difficult to maintain. I think everyone agree on this. Because Java application often only use tables, views and sequences, it is relatively easy for logical standby to replicate.
Logical standby database has unique advantages over physical standby.
  • First you can use it as a reporting server, thus off-load the traffic to primary servers
  • Second you can do rolling upgrade. You can upgrade standby server first, do a switchover, then upgrade old primary server, then do a switchover. For oracle 10g, you can do a major upgrading, from 10g R1 to 10g R2. According to Oracle, you can even upgrade from 10g to 11g. This will achieve zero downtime. Very appealing to environment requiring high availability.
  • Another very useful point is that you can make logical standby work as a test server as well. You can use the command “alter database guard standby”. This will prevent the developer from modify the replication from primary. However, they can create new schema on standby database and do various testing.
    The server use for standby database usually has very similar power as primary, the test is very close to product environment.
    Since you have to maintain this logical standby database, so making it as a test server wont add too much extra cost to you. You can reduce the number of test servers.

November 08, 2006

refactoring code

A utility class

public class AUtils{
 public static void funcationA(){
  Map valueA = callMe();
  func_A(valueA);
}
 public static void funcationB(){
  Map value A = callMe();
  func_B(valueB);
}
}

Better to refactor to this:

public class AUtils{
 private Map valueA;

public AUtils(Map map){
  valueA = map;
}

 public void funcationA(){
   func_A(valueA);
}
 public void funcationB(){
  func_B(valueB);
}
}


November 07, 2006

Singleton in Spring

Follow-up to Singleton in Spring from Oracle/Java/Others

A spring bean default to be singleton. The following class is a Spring bean

Class Transform{
   private Map errors = new HashMap();
   public void setErrors(final Map errors) {
        this.errors = errors;
  }
  public void transform(){
   if(errors.isEmpty()){
    // do something
  } 
}

}

One thread call setErrors() and call transform() to finish it job. The next thread has to remember to call the setErrors() before call transform(), otherwise it will get the values of previous thread.

might safter to change the method signature to

Class Transform{
  public void transform(Errors errors){
   if(errors.isEmpty()){
    // do something
  } 
}
}

So you do not need to call the setErrors(), which is forgettable.


Search this blog

Search Warwick Blogs

 

Tags

Most recent comments

  • Oracle 11g is the clear leader in this area. Oracle has invested heavily into self–tuning capabiliti… by shaane on this entry
  • All the features are very nice.I like Repair Advisors the most.Oracle 10G introduced some of the dat… by lucy on this entry
  • "logical standby failed to re–start, I am also getting the same error. I have search on internet and… by anemia on this entry
  • Thanks for the nice information because from last three days i am stuck on this problem…. by robot vacuum on this entry
  • So what happen City speed dating when you tried this coding once in your PC.. Please tell me so i am… by John Bergeron on this entry
RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXXII