12/23/2009

HireBug

On the last DevClub meeting I presented a HireBug - a "server-side Firebug".

This is presentation in russian:
http://www.slideshare.net/asolntsev/hire-bug

Update: presentation video (also in russian):
http://www.devclub.eu/2009/12/29/andrei-slontsev-hirebug/

11/27/2009

Vaadin demo with Maven

I like Vaadin - Java web framework created by Finnish guys from ITMill.

Vaadin homepage: http://vaadin.com

This is demo web application built with Vaadin+Maven which performs search files on server.
It was really easy to create it!



All you need is to include Vaadin depenency to your pom.xml and create class that extends com.vaadin.Application. No any XMLs, jsp etc.


Full source code:
http://dl.dropbox.com/u/2856647/vaadin-demo-webapp.zip

Screencast:
http://dl.dropbox.com/u/2856647/VaadinDemo.swf

Short overview of Vaadin: http://www.streamhead.com/vaadin-promote-great-gwt-toolkit/

11/26/2009

Jetty Runner

What is JettyRunner?
Jetty Runner is an Eclipse plugin that allows developer to easy run web applications from your projects.

How it works
- Scan all projects in workspace
- Detect web applications projects
- Let user choose web applications to run
- Let user choose the database to connect to
- Run Jetty

Presentation
http://www.slideshare.net/asolntsev/eclipse-jetty-runner

Screencast
http://dl.dropbox.com/u/2856647/JettyRunnerDemo.swf

Installation
Write me in comments if you are interested. Then I will publish the sources/binaries.

PS. This plugin was presented at Eclipse DemoCamp in Tallinn 27.11.2009

5/20/2009

ThreadSafeDateFormat

Problem
As known, Java class SimpleDateFormat is not Thread-safe.
It means that you cannot declare a static member DateFormat in class:

private static final DateFormat DATE_FORMAT = new SimpleDateFormat( DATE_PATTERN ); // WRONG!

Using this member by 2 concurrent treads will lead to error.

What is a solution?
One solution is to create new SimpleDateFormat( DATE_PATTERN ) each time you need to parse a date. Another solution is to create a Thread-safe version of DateFormat.

That's it:


import java.lang.ref.SoftReference;
import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Thread-safe version of java.text.DateFormat.
* You can declare it as a static final variable:
*
* private static final ThreadSafeDateFormat
* DATE_FORMAT = new ThreadSafeDateFormat( DATE_PATTERN );
*/
public class ThreadSafeDateFormat extends DateFormat
{
private static final long serialVersionUID = 3786090697869963812L;

private final String m_sDateFormat;

public ThreadSafeDateFormat(String sDateFormat)
{
m_sDateFormat = sDateFormat;
}

private final ThreadLocal m_formatCache = new ThreadLocal()
{
public Object get()
{
SoftReference softRef = (SoftReference) super.get();
if (softRef == null || softRef.get() == null)
{
softRef = new SoftReference(
new SimpleDateFormat(m_sDateFormat) );

super.set(softRef);
}
return softRef;
}
};

private DateFormat getDateFormat()
{
return (DateFormat) (
(SoftReference)m_formatCache.get()).get();
}

public StringBuffer format(Date date,
StringBuffer toAppendTo, FieldPosition fieldPosition)
{
return getDateFormat().format(
date, toAppendTo, fieldPosition);
}

public Date parse(String source, ParsePosition pos)
{
return getDateFormat().parse(source, pos);
}
}



The main idea of this class is storing separate instances of SimpleDateFormat for separate Threads in ThreadLocal variable. If 2 concurrent threads try to parse date, the will use 2 different instances of SimpleDateFormat.

3/14/2009

Functional Programming in Java

This is my seminar about Functional Programming and using its ideas in Java.

It was done in year 2006.

http://www.slideshare.net/asolntsev/functional-programming-in-java