All 35 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
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
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
December 14, 2006
The Element of Java Style
- Title:
- The Elements of Java(TM) Style (SIGS Reference Library)
- Author:
- Allan Vermeulen
- ISBN:
- 0521777682
- Rating:

Rule 6 Break up long lines. Introduce a line break just before with the lowest precedence or, if more than more operator of equally low precedence exsits between each such operator:
return this == object
|| (this.object instanceof MyClass
&& this.field == object.field
Rule 13 Capitalize only the first letter in acronyms
Use loadXmlDocument() instead of loadXMLDocument()
Rule 51 Use “this” rather than “the” when referring to instances of the current class
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.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.
October 25, 2006
JSTL Loop
<c:forEach begin="0" end="${numbers}" var="status">
${status}
<c:if test="${status %2 == 0}">hi</c:if>
</c:forEach>
The value of varStatus represents the name of a scoped variable that you can use to obstain information about the status of the iteration performed by
action.
The following code
<c:forEach begin="0" end="${pageNumbers}" var="i" varStatus="status">
var: ${i} and status: ${status.count} <br/>
</c:forEach>
generates the following output:
var: 0 and status: 1
var: 1 and status: 2
var: 2 and status: 3
var: 3 and status: 4
<c:if test='$( param.cardType =="Visa"}'></c:if>
<c:if test='$( not empty param.cardType}'></c:if>
<c:if test='$( isRight}'></c:if>
<c:choose>
<c:when test='${isRight}'>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
Hongfeng Sun
Please wait - comments are loading


