01- 05-2008
From now on, i will use following address for blogging:
http://denizstij.blogspot.com/
06-Jan-2007
JAVA: Spring eXchange 2008
Skills Matter and Spring Source are organizing one day free course. Please have a look here for more information and registration.
20-Dec-2007
JAVA: JMS, Spring Framework2.5, ActiveMQ
JMS (Java Message Service) is one of the commonly used technolog for enterprise application. Especially with Spring Framework 2.5, design and implementaton of projects with JMS is more easier. I have implemented a skeleton JSM project with following technologies for echoing messages back to sender:
- JSM
- JMX
- Spring Framework 2.5
- Apache ActiveMQ 4.1.1 (ActiveMQ 5.0 has a bug, therefore i used 4.1.1)
- Maven
- Eclipse
That skeleton projects can be improved for tunnelling from one machine to another by using JMS. Full project can be downloaded from here
15-Dec-2007
JAVA-Interruptedexception, C3P0, max_statements, Hibernate, Spring
We were having a serious problem in one of our application which handles millions of record with multithread mechanism. During debug and live, we were getting several InterruptedException either in code and sql side. Hibernate and spring was complaining about current transaction management.
When i debug the code, i seen that rather than catching InterruptedException in Thread.sleep(dur) and dealing with it, it is allowed to propagate the exception upper. Worst thing regarding to InterruptedException is not take any action. Even catching and then swallowing or logging is prevent many problems later.
Of course, InterruptedException was not the cause of failure in the application. It was just a symptom showing that something is wrong in our multithreaded mechanism.
We are using multithread with Spring, hibernate and C3p0. In order to support multithreading we set following parameters in hibernate:
hibernate.current_session_context_class =thread
hibernate.transaction.factory_class =org.hibernate.transaction.JDBCTransactionFactory
hibernate.c3p0.max_statements=30
After some playing with these settings, we noticed that, problem was causing cos of max_statement. For better performence we set max_statement >0. but it seemed in multithreading application, it creates dirty caches. For example, we were not able to retrieve collections from DB.
As solution for time being, we set hibernate.c3p0.max_statements=0. But when we have more flexible time, we are planning to modify our DAO in a way that before each hibernate operation we refresh the ppol or session. I know it seems it will degrade the performance, but at least our mission critical application wont be down. And meanwhile, if you have better solution for the problem, please let me know.
06-Dec-200€7
JAVA-Spring-Framework 2.5
Tonight, i attended a talk about Spring Framework 2.5 by David Syer from Spring Source. I found the talk quite useful. David talked about new features in 2.5 Spring Framework. These are the new main features in 2.5 David emphasized in his talk and I remember:
• Annotation
Even though, David himself is not big fan of annotation, he told us that, new annotation features makes life more easier for coder. Especially in Spring MVC and new test context, new annotation features seems useful to me. Even though, I will still use XML configuration for extrernal settings such as data sources.
• Autowiring
With new version and annotation, autowiring is more easier and unambiguous. Not only type based annotation is possible, but also name of beans can be used for for preventing ambiguous situations.
• TestContext
Mock test classes are renamed to TestContext with more sophisticated features by utilising annotation and autuwiring features. I think, this feature,by itself, is enough to use 2.5 Spring Framework.
Unfortunately, I could not get the link of the presentation. But there is a free one day training on 16 Januray 2008 by CEO of Spring FrameWork. Please register on http://spring-exchange.com to attend the training.
05-Dec-2007
JAVA-Free eBook Better Builds with Maven
14-Nov-2007
JAVA-Free eBook Domain Driven Desing Quickly (DDDq) by Eric Evans.
13-Nov-2007
JAVA-Spring (2.1) vs EJB.3x: Today, i come cross following presentation on EJB3x and Spring. This presentation and a response blog from interface21 (the company behind the Spring Framework) explains in a clear way comparison of Spring and EJB3x. Although, in his presentation, Reza Rahman, is kinda bias to EJB3.x, he gives a good overview of Spring vs EJB3x. He suggest to use Spring and EJB3x in the following cases:
Use EJB 3 if:
• You like annotations and dislike XML configuration.
• You prefer a tightly integrated solution stack that makes sensible default choices for
you and minimizes configuration.
• Your application is very stateful.
• Standardization is an important consideration.
• You use JSF and are considering using Seam or WebBeans.
Use Spring if:
• Your application requires fine-grained control at the container level.
• Your application requires a lot of configuration beyond gluing together components
and resources.
• You need to build your own solution stack (such as with iBATIS, Quartz or Acegi).
• You are likely to extend the middleware framework.
• You need advanced AOP features.
I found following diagrams from the presentation quite useful (altough it is biased to EJB3x) :
EJB3 and Spring architectural Concerns
11-Nov-2007
JAVA-Apache-Commons-HTTPClient: I dont know why but, i have always liked the products of Apache (also google) since my first degree. HTTPClient is one of the common-library of Apache for creating fast, reliable http clients from your java code. By using this lib, i managed to login a secured web page and do some batch operations on my web site (checking a particular bug). In the following link, you can find source code for connecting a secured web page and retrieve the requested pages... Sure, the source code needs further attention, but it is good for a quick start for beginner.
ApacheHTTPExample.zip: Source code and classes (Sure, it needs apache-httpclient and some other common libraries:))
08-Nov-2007
JAVA-(Php)-Regular Expression: Anyone who worked with regular expression in java, perl, php, knows that it can quite tricky to come up with a regular expression which works with complex and dynamic string contents. Think for example, in a text buffer to find out the position of the end of every other couple of sentences. I come up with following long regular expression. I must admit it is not complete. But it would give some idea (in php syntax) :
$minSenLen=1;
$maxSenLen=3;
$pattern="/((\s+?(\P{Lu})\w+?[\.+|\?|\!].*?){{$minSenLen},{$maxSenNum}})(\P{Lu}[\.+|\?|\!+])([\s+?|\"|\)]+?(<br>)?)([\p{Lu}])/";
$strBuf=getStringBufferContent();
// lets put for example, "Booooo\nBeeeee" every other 4th match in the pattern.
$newStr=preg_replace($pattern, "$1$4Booooo\nBeeeee$7", $strBuf);
06-Nov-2007
JAVA-Spring-JDBCTemplate By using subquery and join sql commands retrieving information from tables
/*
* To find the finished job with a given name in a deparment with project manager
* and deployer by using Spring and JdbcTemplate
*
* Job Table : job_Id|job_Name|Job_Type| date_Start| date_Finished |man_ID| dev_ID
* Users Table: user_id|userName|given_name|family_name|
*/
String jobName="BooooWorldProject";
String query=" SELECT "+
" job_Name"+
" job_type"+
" man_ID"+
" dev_ID"+
" concat(u.given_name,' ', u.family_name) as manager_name"+
" concat(u2.given_name,' ', u2.family_name) as developer_name"+
" d.date_Start"+
" d.date_Finished"+
" FROM " +
" ( " +
" SELECT * FROM "+
" ( "+
" SELECT * FROM jobsTable "+
" WHERE " +
" job_status='FINISHED' AND" +
" job_type=22 AND "+
" job_Name = '"+jobName+"'"+
" ) as j"+
" JOIN (SELECT given_name, family_name, user_id FROM users) as u"+
" ON u.user_id=j.man_ID ) as d"+
" JOIN users u2"+
" ON u2.user_id= d.dev_ID";
Collection clients=this.getJdbcTemplate().query(query,
new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Jobs job = new Jobs();
job.setName(rs.getString("job_Name"));
job.setJobType(rs.getInt("job_type"));
job.setMangerId(rs.getInt("man_ID"));
job.setDevID(rs.getInt("dev_ID"));
job.setManagerName(rs.getString("manager_name"));
job.setDevName(rs.getString("developer_name"));
job.setDateStart(rs.getDate("date_Start"));
job.setDateFinished(rs.getDate("date_Finished"));
// here, jobs can be processed too..
return jobs;
}
});
31-Oct-2007
JAVA-Maven Changing the source directory of test code in maven:
<build>
<testSourceDirectory>path_to_your_tests_directory</testSourceDirectory>
....
</build>
14-Oct-2007
JAVA Total Number of Classes in Jore Java
Have you ever wondered how many core java classes have? For a java source generator project, i needed the list of standard classes for inserting import definitions (such as import java.util.List) in source code which i generated. By utilising rt.jar (core standard java files JVM uses at Runtime.jar) as following source code, i obtained the list of class files in java.
So the answer of my question: there are 15919 classes in java 1.6.0_02. Please note subclasses are also counted. Please filter them if you wish by utilising following code:
public static List <String> ListOfCoreJavaClasses(){
List <String> classList= new ArrayList <String>();
String javaDir=System.getenv("JAVA_HOME");
String sp=System.getProperty("file.separator");
String rtJarLoc=javaDir+sp+"jre"+sp+"lib"+sp+"rt.jar";
File rtF=new File(rtJarLoc);
if (!rtF.exists()){
log.error("rt.jar is not located at"+rtJarLoc);
log.error("Exiting...");
System.exit(0);
}
log.debug("Extracting class list from "+rtJarLoc);
FileInputStream fis;
try {
fis = new FileInputStream(rtF);
BufferedInputStream bis= new BufferedInputStream(fis);
ZipInputStream zis= new ZipInputStream(bis);
int i=0;
while (true){
ZipEntry zipEntry= zis.getNextEntry();
if (zis.available()==0 || zipEntry==null)
break;
// Bear in mind, it also has subclasses
// Filter out classes which contains
//$ in their name if you need.
classList.add(i,zipEntry.getName());
log.debug(zipEntry.getName());
i++;
}
log.debug("Total number of classes="+i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return classList;
}
JAVA-Event: EclipseWorld 2007, November 6-8, 2006, Reston, VA
A show dedicated to learning all things Eclipse including plug-ins, SWT, debugging, RCP, BIRT, the Test Tools and Performance Platform, Web Tools, and so forth.
10-Oct-2007
JAVA-Personal Project: EmasS: Personal Email as Personal BackUp Storage
I dont how many times, it happened to you, but quite few times, i lost my important document, projects cos there were not a secure and free place to backup my files. Having gmail, yahoo and hotmail increased their email storage capacity, email address would be used for backup purposes. I store many of my file in my emails. But there is only an issue: These email providers allow only a limited size of attachement (max 10 MB at the moment). But if you have bigger files (for example, my whole PhD thesis, in zip format, was more than 100MB), than they dont allow you to send this files as attachment...
This utility program aims to use your email address as backup storage. It compresses your file and then divides it into small partions and then sends it to your email address via SMTP. And when it is wished, it uses POP3 protocol to fetch the pieces and the combine and finally unzip and bring your file.
The project uses following technologies:
- Javamail - for SMTP and POP3
- java.util.concurrent .ExecutorService (newCachedThreadPool) APIs for multihreading (sending emails by using SMTP )
Usage :
java -cp classpath -jar JARNAME [-c file] [-x keyword]
-c file: for backuping the file
-x keyword: retrieve the files which has "keyword" in their names (Please make sure it is unique in your inbox)
Configuration:
"resource/email.properties" file holds information for the SMTP and POP3 protocol. Please modify it for your personal usage."emass.blocksize" key holds the size of each piece. For example, following set up each piece 5KB (5000)
emass.blocksize=5000
Notes:
- This is a beta version and implemented for giving some idea how email address can be used for personal backup (or maybe for P2P ;-)).Please feel free to use but acknowledge.
- Please use a standart POP3 service. Unfortunately, since Gmail does not provide standard POP3 service, this application is not robust on Gmail (Although, if gmail POP3 setting is set to fetch up to download all email before downloading backup piece files, gmail is also would be used). Author advices to use standard POP3 services, such as pop.yahoo.com
Download: Source code and dependency libraries
08-Oct-2007
JAVA Log4JLogger not found exception
For a personal framework, I decided to use a apache's common logging. When i start to test with log4j, whatever i do, i could not get log.debug(msg) log messages. I thought it would be maybe cos of my loggin settings in log4j.properties. But whatever i did, it failed.
So i debuged the source code, and i noticed that my framework uses deafult Jdk14Logger rather than Log4JLogger implementations, even tough i imported log4j libraries for the logging operations for the testing.
So I explicitly imported Log4JLogger as follows:
prop.put("org.apache.commons.logging.Log","org.apache.commons.logging.impl.Log4JLogger");
But i got following error in eclipse:
org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable
Actually, exception message is quite clear. It indicates that it can not find the log4j library (log4j.jar). But the problem is that it is on my build path of eclipse project (with happyly together commons-logging.jar) and i should not get this problem.
So i started to analyse the problem. First, I checked if i have a "commons-logging.properties" which overwrites my configuration of common-logging. Nope. There was not.
So enabled the diagnostics of common logging as follows:
System.setProperty("org.apache.commons.logging.diagnostics.dest", "STDOUT");
There i noticed, LogFactoryImpl of common loggin, uses some other commons-logging.jar in the class path. Actually, in eclipse setting, order of this library is far behind then the other one which is together log4j.jar, but LogFactoryImpl implementation uses different mechanism when discovering log4j libraries.
Anyway, after placing log4j.jar with commons-logging.jar in the classpath, the problem is disappeared..
07-Oct-2007
BOOK A Thousand Splendid Suns by Khaled Hosseini
Recently, i have finished reading that amasing book. It tells so touching story of two Afgan women after 1970's till now ( mids Soviet occupation, jihad, Taliban and finally NATO peace keeping force) . I must admit, in terms of style, and story telling, it is not the best book i have read, but the presentation of the unfortunate life of these two women in Afganistan is amasing. I must say that, when during reading the book, sometimes i felt that Hosseini told the story from a westerner eyes, rather than muslim-assian. But overall, it is must-read book. i strongly suggest this book, to see the affect of the war on ordinary people.
05-Oct-2007
JAVA Simple Date Serve with RMI Spring with RMI Spring
Spring provides a powerful platform for RMI applications. In a matter of 5-10 minutes, an efficient RMI application can be created. Please note, Spring library files and especially spring-remoting.jar has to be in classpath when client accesses to RMI server, as when spring exports the service to the RMI server, spring utilises its own libraries (ClassNotFoundException: RmiInvocationWrapper_Stub error indicates you need to add spring-remoting.jar to class path).
JAVA-eBOOK Hibernate Annotation
An e-book about Hibernate Annotation for those who does not like XML mapping and configuration. Hibernate Annotation is a powerful technique when using hibernate. It prevents you writing complicated, long XML mapping and configuration files. But on the other hand, using annotation means, hard coding in other word, for example, if you change name of table or column in database, you have to recompile your code again.
02-Oct-2007
JAVA MyRSS: An example to show TimerTask and Timer in JAVA
eBOOK- Hibernate In Action
28-Sep-2007
JAVA Source code diagram [Pdf, Zip(rar)] of hibernate-shards-3.0.0.Beta2 with DoxyGen
14-Sep-2007