Do you know how to use lazy initialization in Java? There’s already many thread discussing this problem in the comunity, just to conclude here.
Due to the JVM memory model, Double-Checking Locking (DCL) will not work in Java, I’d like to recommend two articles talking about this.
The "Double-Checked Locking is Broken" Declaration
Double-checked locking and the Singleton […]
Archive for the 'Tech' Category
I ever write an article about the event handling of Java and C#, just want to add some of C#’s delegate.
Delegate has no semantics carried, so does interface, it only provide method signatures.
Let’s look at the following example:
class Person
{
public interface Runnable
{
void run();
}
public […]
JAVA SE 5.0 provides two very useful APIs to help us debug our program, All this two are all class "Thread"’s method:
public StackTraceElement[] getStackTrace()
Returns an array of stack trace elements representing the stack dump of this thread. This method will return a zero-length array if this thread has not started or has terminated. If […]
One of my US friends ask me how to offset the timestamp of Lilina RSS aggregator. He lives in the east coast but his web host is in the west.
In fact, it’s very easy to do that, and I do think Lilina should add such support.
1) Add the following line in "conf.php"
< ?php
$TIMEZONE_OFFSET = […]
JSR223 "describe mechanisms allowing scripting language programs to access information developed in the Java Platform and allowing scripting language pages to be used in Java Server-side Applications."
This defines a framework to allow scripting language programs to access information developed in the Java platform. We currently plan to integrate this into Mustang for b40. Aside from […]
Actually, this article is posted about one year before, at here. Today, I happened to see this article, interesting. So, I found my old entry and post here. Also, I post all the comments at the end, it’s really valuable I think.
Recently(2004.08.06), a friend of mine discussed the Event handle issues in C# and […]
Interesting topic, right? One of my friends encounter this problem when he’s applying software engineer position in a company.
Suppose we have only stack available
Stack* stack_init();
void push(Stack*, int);
int pop(Stack*);
void stack_free();
Please implement the following interface of queue
Queue* queue_init();
void inq(Queue*, int);
[…]
A useful tip to share with you.
I need to read the file from the current directory (same directory with the main jar file). In my code, I just use "new File("test")", and it works quite well.
But in my colleague’s machine, it throws the FileNotFound exception. Oh, we I saw the exception in his screen, […]
These days, I have investigated the Netbeans RCP(Rich Client Platform), and developed some module on it. Netbeans is not only the Java IDE, Netbeans.org has provided netbeans platform as an application runtime for build rich desktop application, just like eclipse platform. The “plugin” here is called “Module”. Every module is a “nbm” file that could […]
Today, my friend ask me to review some code of him, his code will encounter some unexpected error. He’s very confused and worried. After digging into the code, I found the problem.
Here’s the code slice :
private boolean done;
private Message[] messages;
… …
synchronized(this) {
if(!done || messages ==null) {
// 1
try {
wait();
// 2
} catch (InterruptedException e) {
e.printStackTrace();
}
…
dispatchMessage(messages);
// […]
