Hi, my name is Timo Ernst and I am a web expert.

Archive for the ‘Nerd stuff’ Category

New project: zkexamples.com

Posted on: May 17th, 2011 by Timo

I created a new online platform called zkexamples.com.

The goal is to provide really simple and quick examples for common ZK use-cases and requirements (what is ZK?).

The idea is based on flexexamples.com which was a great help to me when I was coding a lot of Adobe Flex.

If anyone has some nice examples to share, feel free to sign up and just post it (requires review and approval by me).

I, personally, try to post every time I learned something new about ZK.
Might help someone else who has the same problem.

TwitterDiggFacebookShare

Quickfix: Hibernate integration for ZK applications

Posted on: April 24th, 2011 by Timo

If you’re using the awesome ZK framework together with Hibernate you might run into some issues where Hibernate behaves a little funky while the application runs.

The trouble’s cause

According to the developers of ZK, the reason for this is ZK’s multi-threaded event model. Whenever an event gets fired, a new event thread is created. This will lead to multiple instances of the Hibernate session class (one per thread) and thus lead to unpredictable behavior.

The quick fix

If you don’t want to read the whole blah-blah in the linked article, here is the quick fix. Just insert the following lines into your zk.xml file and you should be fine:

<!-- Hibernate SessionFactory life cycle -->
<listener>
<description>Hibernate SessionFactory life cycle</description>
<listener-class>org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener</listener-class>
</listener>

<!-- Hibernate OpenSessionInView life cycle -->
<listener>
<description>Hibernate Open Session In View life cycle</description>
<listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
</listener>
TwitterDiggFacebookShare

Vector vs. ArrayList in multi-threaded Java applications

Posted on: April 20th, 2011 by Timo

I lately had to play around a lot with collections in multi-threaded environments and learned several new stuff that I’d like to share:

Vector vs. ArrayList

Where is the difference between both? When should you use ArrayList and when is the time to use Vector?
This is a very common question and often leads to huge discussions.
For me, the following two points are sufficient in order to decide when to use what:

  1. Vector is threadsafe. ArrayList is not.
    That means that you can have two threads accessing (and manipulating) a vector without having to worry about mutual exclusion.
  2. ArrayList is a little faster than Vector but not threadsafe.

Lists in multi-threaded environments

Now, if you have multiple threads in your application which both access collections at the same time, you might run into issues because this is simply not allowed. Think of the list as a piece of cake. Only one guy can eat it.

As mentioned above, Vector is threadsafe, so in theory you could assume that it’s perfectly alright if you only use Vectors through the whole application. That’s wrong. See the example below, which will cause a ConcurrentModificationException.

So, if you have thread 1 doing this:

List<Person> persons = new Vector<Person>();
fillList(persons);

for (Person person : persons){
	if (person.getName().equals("timo")){
		doSomething(person);
		persons.remove(person);
		break;
	}
}

.. and thread 2 does the same thing at the same time, you’ll most likely face a ConcurrentModificationException.

That’s because

  1. The “for (Person person : persons)” syntax creates an implicit iterator which is not thread safe.
  2. You cannot iterate over a collection and modify it at the same time.

Solution: Use the synchronized keyword and iterate over a copy but modify the original

List<Person> persons = new Vector<Person>();
fillList(persons);

synchronized(persons){
	List<Person> copy = new Vector<Person>(persons);
	for (Person person : copy){
		if (person.getName().equals("timo")){
			doSomething(person);
			persons.remove(person);
			break;
		}
	}
}

Wrapping the for loop into a synchronized block will synchronize access between multiple threads.
This must be done in all threads which could possibly manipulate the vector. Adding the synchronized keyword in just thread 1 will not work unless thread 2 also uses this keyword.
Also, the above code creates a copy of the original list and iterates over it. Note that the call of persons.remove(person) happens on the orignal list.

TwitterDiggFacebookShare

The perfect syncing solution for Android-based devices on Mac computers

Posted on: December 10th, 2010 by Timo

I own a HTC Desire for quite a while now (actually since it came out) and I’m still very happy with it – and YES, I used an iPhone before and I’d never trade it for my Desire. However, one thing that really annoyed me was that synchronization was not as smooth as on the iPhone, where you could just connect the device, fire up iTunes and that’s it. The reason for this is that HTC does not offer its software called “HTC Sync” for Mac computers (boooo, HTC!). Thus, I needed a decent synching solution for my Android phone that also works on a Mac.

The first attempt: DoubleTwist

So, I started googling around and the first thing that I found was DoubleTwist, which calls itself “iTunes for Android”. After giving it a chance for some days, I realized that this piece of software seems to be pretty buggy. Whenever I synced between my HTC Desire and the iTunes library, something went wrong, for example missing songs or even duplicates. To sum it up: It was unusable. On top of that, the integrated Amazon store, where you could buy and downloads songs from, is not available here in Germany. Epic fail, I’d say. At least it’s for free.

Salling Media Sync

After being disappointed by DoubleTwist, I had to manually sync my computer and smartphone by copying files between them. No need to say that this was definitely an unsatisfying solution. So, today I stumbled over a really nice tool called Salling Media Sync. It doesn’t include a music store. Instead, its only purpose is to sync your Android device to the iTunes library. Just what I needed, I thought and downloaded it right away. Installation was easy (since there is none). Just copy the *.app file to your application folder and that’s it. Once started, Media Sync instantly found my smartphone (wow!) and displayed some information about it (free disc space etc.). After selecting the media which I wanted to sync (music, podcasts, pictures) I pressed “sync” and that’s it. How easy is that? I was really impressed how simple Media Sync works.

The application itself is now available in the quick launch bar on the top right of your mac screen and automatically starts when the Mac has booted, so whenever you connect your Android device, Media Sync will check if synchronization is required and if yes, it will do that:

Costs

The basic version of Media Sync is free. You can just download and use it as long as you want. The only downside here is that whenever the application synchronizes your phone, it will copy all files, which is often not required and can take quite a while, especially if you carry a lot of gigabytes with you, like I do.
So, if you don’t want that, I recommend spending 15 EUR and purchase the full version which supports smart synching. That means, that Media Sync will only copy the files which are really necessary. This way, the whole synchronization process gets a lot faster.

I am really happy now with Media Sync. The 15 EUR are absolutely worth spending.

TwitterDiggFacebookShare

Me, my Hengedock and why I cannot recommend it

Posted on: November 15th, 2010 by Timo

I own a 13″ Macbook Pro (mid 2009er version) and from the first day since I have it, I can say without alacrity that it’s definitely the best notebook that I ever had but there has always been one thing that annoyed me when I used it on an external display in “desktop mode” (with the macbook closed): Whenever I wanted to use just the laptop itself in with the build-in display, I had to unplug all the cables for display port, usb (x2), power and sound. That was really annoying especially if I wanted to plug it back to the external display. Since then, I was searching for a decent docking solution where I could just put in the macbook and take it out without having to fight with a horde of cables. This search lead me to Hengedocks. Now, after almost a month of usage, I must say that I am pretty disappointed.

Update: Make sure you check out my NEW review on the 2nd generation of Hengedock after reading this.

You might have heard about Hengedocks before. They are often mentioned in various Mac forums and their look definitely fits well to Apple hardware. The product videos on their own website suggests high quality. On top of that, Hengedocks seems to have heavy issues delivering the docks due to high demand. If so many people want it, they must be good! – That’s at least what I thought. So I tried to buy one.

After being on the waiting list for almost forever, I finally succeeded in purchasing one in England through the Amazon store. Seems like as if some clever company bought some of the docks and sells them now in the UK. So I ordered one and only after a few days it arrived here in Germany pretty quickly.

Installation and first impression

There was not much inside the package. Just the dock, a few screws, a special screwdriver, extension cables and the manual. Installation also is pretty easy. You basically have to plug-in a cable to your Macbook, then put the laptop into the dock, make sure it’s aligned correctly and then you fix the cable with one of the screws (which can leave a mark on the cable heads). Then you pull out the Macbook and you do the same again with the rest of the cables – one by one. This procedure seems to be important so that the Macbook is always in touch with the cable ports when you slide it into the dock. The manual also points out that it is vital for the health of both, the dock as well as the notebook, to not use force. If you ever have to push or pull hard at some point, you’re doing something wrong.

One important thing regarding the cables is that you must break off the clip at the ethernet network cable head, as described on the Hengedock website. If you don’t and you plug the Macbook into the dock, there is a chance that it will get stuck.

Another thing that kinda annoyed me is the incompatibility with the power supply cable of Apple’s 27″ Cinema Display. I was so glad when I bought the display believing that it could replace the standalone power supply cable of the Macbook but unfortunately it doesn’t fit into the dock. So I had to use the old original power supply adapter + cable from the Macbook. Disappointing, isn’t it?
For the new upcoming models of the docks, it seems like there are some adapters included to the package which should solve the problem. However, I don’t have one and to be honest: I don’t feel like importing a piece of plastic worth around 5 bucks from the US here to Germany.

Update: I asked Hengedock support if they separately sell those adapters. They don’t:

“Currently the MagSafe Adapter tool is not available to purchase separately – it comes included with all of the new generation docks with which it is compatible.”

After installing all the cables everything seemed to look alright, so I wanted to turn on the machine, but wait. How do I do that with the closed Macbook standing inside the dock? Simple answer: You can’t. So I had to pull it back out, open it up, turn it on quickly, close it (so it doesn’t go into standby mode) and then gently put it back into the dock. I could already see myself doing that at least once a day since I always completely turn off my Macbook during the night. For daytime, I simply wake up the computer from standby by pressing a random button on the keyboard.

After some seconds, Mac OS boots and I can see the desktop on my external display. Network also works and the power supply cable led turns red which means that it’s charging the battery now, so everything seems to be ok.

Four weeks later

Before I go into detail on the dock itself, you might find it interesting that I still haven’t head a word from my reservation on the original Hengedock website. I’m so glad that I ordered on Amazon since I really hate waiting.
Update: Now, about 2 months later, my pre-ordered Hengedock is available. Bit to late.

However, after using the dock for a while now, I can say that I am definitely a bit disappointed. The look is good and having a dock for my Macbook is definitely a relief, but there are more disadvantages to it than I initially thought.

First, as described before, installation is not as smooth as it could be:

  • Cinema Display power supply cable head doesn’t fit.
  • I had to destroy one of my ethernet cable heads in order to use the dock T.T – Not funny if you do that to long and thus expensive cables.
  • The screws that fix the cables into the dock leave a mark on the cable heads.
  • You cannot turn on the Macbook while it’s in the dock.

Another issue that I want to mention is audio support for headphones. There are extensions delivered with the Hengedock that you can plug into the Macbook’s audio port but they’re basically useless because if you do so, the internal speakers will stop working (and so do the external speakers of my Cinema Display which get their audio signal through USB) because the Macbook thinks that there are headphones attached to it – but actually there isn’t. It’s only the extension.
So, regarding audio, you have the choice: Either you simply cannot use headphones (which is the choice I took for the moment) or you’ll have to get some external speakers, and attach these together with your headphone to the audio extension through an Y-cable. That way, you have sound through both – speaker AND headphones.
As an alternative you could also use USB or Bluetooth-headphones.
Using the Apple Cinema Display together with “classic” audio-port based Headphones will not work though (at least, I see no way how).

Update: I forgot that you can actually choose the source and output for audio signal in Mac OS preferences :-)

Well, so after getting over these initial problems, I observed another critical issue. According to Hengedock, the dock is not supposed to scratch the Macbook but they do leave some marks to the surface. See the picture above where the red circles mark the parts where these marks occur.

These marks aren’t bad. Until now, I was able to polish them away with a soft towel but what happens after 2 or more years of usage? I can’t believe that this is good for the surface of the Macbook. The dock itself simply seems to be to tight and its plastic casing is just to hard. So whenever I put the laptop out or into the dock, I can already hear how it’s scratching. I don’t know how others think about this but: I don’t like it. Why didn’t they line in the inside with some soft texture? That would’ve made it easier to plug and unplug and there were no marks to the surface.

Update: As pointed out by Henge Docks CEO Matthew Vroom, the dock is made of a material which is softer than the Macbook’s aluminium. This makes it impossible that the dock can actually scratch the notebook. So, apparently actually the opposite seems to apply: The Macbook scratches the dock. This leaves some marks on the laptop’s surface, which can be removed with a wet towel (a dry one didn’t work well for me).

In a nutshell

To sum it up, I cannot recommend the Hengedock as a good docking solution for a Macbook Pro (13″). It looks good yes and you won’t have to manually (un-)plug the cables whenever you want to move the laptop but that’s all.