kafka vs. kavka
als ich letzte Woche mit freunden (oder sagen wir lieber bekannte) im irish pup saß, sprachen wir kurz über die bücher kavkas. Das klang dritte erstmal recht intellektuell. zugegeben fällt es auch schwer nur beim hören zwischen kafka und kavka zu unterscheiden. nicht der alte franz hatte es uns angetan sondern markus. Read the rest of this entry »
Open issues with SimpleDateFormat & a brief introduction to joda-time
last week i used the [tag]jprofiler[/tag] to scan our applications for bottlenecks. after just a few minutes i detect that we make really heavy usage of the java.text.SimpleDateFormat class. Using this class in occasional formatting jobs normally causes no problems. But invoking the parse and the format method more than 500.000 times during application startup can definitely cause some performance issues. I identified three problems while working with SimpleDateFormat which are more ore less related to each other:
- [tag]SimpleDateformat[/tag] isn’t threadsafe
- The creation of an SimpleDateFormat is a relativly heavy operation
- the parser methods have a bad performance
my first approach to fix problem #1 and problem #2 was to introduce a SynchronizedFormatter class which implements synchronized methods for parsing and formatting Dates. This SynchronizedFormatter can be called in a static context, so i needn’t so much Formatter objects.
After fixing that, i profiled the app again and still had to handle problem #3. when running an java app with the jprofiler agent, the parse method takes about 50 microseconds. of course thats not the time it would take in operational, mode but nevertheless 500.000 invocations will leave their mark during application startup.
While browsing some java forums i discovered a great library. joda-time replaces the java date and time classes. The homepage listed a lot of reasons why to use their implementation instead of the classes out of the jdk box. Besides the easy to use api and the comprehensive feature set they mention better performance characteristics which definitly match my actual needs.
After replacing all usages of the java.text.SimpleDateFormat by org.joda.time.format.DateTimeFormatter in my app I profiled my app a last time. Since the formatter class of [tag]joda-time[/tag] is threadsafe, I could simply replace my just written SynchronizedFormatter class. The parsing methods of jodas DateTimeFormatter took about 4 microseconds (about ten times faster than the SimpleDateFormat implementation) and the overall startup time of the app reduces dramatically.
If you do lots of formatting, parsing or calculation operations in your java applications you should definitely take a look at the joda-time library! this lib is really impressive!
regards René
thougts about java7
Today I took some time to take a deeper look at [tag]java7[/tag]. in contrast to java6 the update to version 7 contains some language improvements again. In this post I take a quick look at some of these new language features.
1. Safe NULL-handling
I’m really glad to hear that for example the safe nullpointer dereferencing we already know from [tag]groovy[/tag] will be part of the java language. The syntax seems to be the same as in groovy. the safe dereferencing operator “?” can be used to avoid Nullpointer Exceptions in your code:
1 2 3 | public String getPostcode(Person person) { return person?.getAddress()?.getPostcode(); } |
Instead of causing a NPE if person is a null object, the return value of this method will be null.
Another feature about safe handling with null objects is the null-default operator. In Java7 we happily needn’t write code like the following anymore:
1 2 | String str = getSomeStringProperty(); str = (str != null ? str : ""); |
Writing str = str ?: “”; will do the trick.
These two improvements seemed to be heavily inspired by the groovy dynamic language. But it’s a pity that the groovy truth (null==false) apparently isn’t part of of java7, although the null-default handling is a part of that.
2. Improved catch clause
In Java7 it will be easier to handle two types of catched Exception by introducing the following syntax:
1 2 3 4 5 | try { return new ExampleClass(); } catch (InstantiationException | IllegalAccessException e) { throw new AssertionError(e); } |
You can concatenate two or more exceptions, which you want to be handled the same way, by the using the new “|” operator. I think this is real code sugar. It will safe much lines of code. Till today i wrote private methods if I have to handle the same complex exception handling on different catched exceptions. Now this isn’t necessary anymore.
3. switch statement with a string
I guess many developers wonder why this feature is not yet part of the Java language. I don’t often use switch statements. But if I use it, I really often miss that feature. Since Java7 the switch statements with string values (just like we already use in groovy) will be part of java.
4. Chained Invocation
A really nice new feature will be the support for chained invocation. what does this mean? think about the following code:
1 2 3 4 | Person person = new Person() person.setFirstname("Peter"); person.setSurname("Fox"); person.setAge(42); |
This code isn’t really handsome. you have much boilerplate code for just creating a person. this maybe can be solved using constructers with lots paramters. This isn’t really nice stil. To avoid this boilerplate code the developer can profit on the new chained invocation feature. java7 allows void methods to implicitly return this. this results in the following java7 code:
1 2 3 4 | Person person = new Person() setFirstname("Peter") setSurname("Fox") setAge(42); |
Btw, of course it is already possible to write this code in java5 and earlier, but this requires a breach with the java bean model since you have return this explicitly.
This was just an abstract of the complex java7 topic. I’m really looking forward to the java7 release. Since coding a lot of groovy code the last days, I am a spoiled child who doesn’t want to miss these features in his daily java development.
Finally excuse this bunch of language mistakes. Writing blog entries in english seems to be a good excercise for me and I determined, that english entries achieve more readers than german written ones.
kultur-update II
kurz vor weihnachten kam ich noch in den genuß den besten b-movie allerzeiten zu schauen. hier der trailer zu “death race 2000″:
[youtube qbKKCCmh7GU]
[tags]bmovie[/tags]
gruß brs
kultur-update
bin quasi gerade erst ausm knapp 4 wöchigen urlaub gekommen (heute lassen wir mal weg). dabei hat sich einiges an links und musik angesammelt. fangen wir mal mit ner cd empfehlung an.
als ich so durch die republik gefahren bin lief plötzlich philipp poisel im radio mit dem lied “mit jedem deiner fehler”. nachdem ich mal das album “wo fängt dein himmel an” durchgehört hab steht fest, dass ist kein one-hit-wonder. als klar gibts hier gleich mal nen link zu youtube: [youtube Ey5fY5msniI]
als nächstes dann ein lied was ich schon vor ewigkeiten gehört das erste mal gehört hab. es handelt sich um josh radin mit “winter”. eventuell kennen fans der serie scrubs das lied schon. mit diesem song wird folge 16 der 3. staffel beendet. abgesehen von diesem lied ist der soundtrack der serie insgesamt sehr genial. zu verdanken haben wir das zach braff. der ist nicht nur hauptdarsteller, regiseur und drehbuchautor der serie, sondern größtenteils auch für die musikalische untermalung zuständig. hier nun der song:
[youtube cHlf08yTPiU]
Als bekennender TEX fan (danke dabei an robert) ist das echte highlight allerdings
TV-Noir. was das ist erklären die macher am besten selbst:
hier ein ausschnitt von deren homepage:
TV Noir – das Wohnzimmer der Songwriter ist eine Berliner Talk- und Musikshow, die man live, im Fernsehen und im Netz sehen kann. Live: Immer 1. Sonntag des Monats um 20:00 Uhr im Cafe Edelweiß in Kreuzberg
ausschnitte der sendung gibts auf youtube zu sehen. hier mein momentaner favourit von tvnoir.de und auch die antwort auf eure frage, was das ganze mit TEX zu tun hat. es handelt sich dabei um eine variation von “die kaiser von china” zusammen gesungen mit eva briegel (bekannt durch die band juli)
[youtube msipnGXEAvU]
[tags]TEX TVNOIR scrubs[/tags]
ein paar songs fallen mir noch ein, die gibts aber später mal.
gruß rené
das blog jahr geht zu ende
eigentlich wollte ich ja noch das update auf wordpress 2.7 dieses jahr noch machen. leider kam das final release erst so spät, dass ich es nicht mehr schaffe und über die feiertage wohl beim beta3 release bleibe. stattdessen verabschiede ich mich heute in den urlaub über die feiertage. bis mitte januar gibts hier keine neuigkeiten. gelegentlich werd ich mich zum twittern hinreißen lassen.
wie gesagt knapp 3 wochen urlaub. hab einige bücher dabei und hoffe ich komm dazu die zu lesen. schaun wa mal
frohes fest und guten rutsch,
gruß brs
wordpress update
der blog läuft jetzt auf wordpress v2.7b3. das update lief echt sehr unproblematisch. bei gelegenheit muss ich mal mein theme überarbeiten.
mfg admin
marcel melde dich
gestern ließ pro7 wieder seinen urin kellner von der leine gelassen um mal wieder fröhlich das deutsche volk zu verarschen. wer es wie ich verpasst hat, hier gibts die zusammenfassung zum untergang des abendlandes:
http://www.spiegel.de/kultur/gesellschaft/0,1518,590702,00.html
ein freund fragte grad was wohl reich-ranicki dazu sagen würde wenn er es gesehen hat. jetzt bin ich um den guten marcel ein wenig besorgt. wenn er beim zappen drüber gestolpert wäre, hätte er sich wohl gleich in seiner bibliothek den strick genommen. — marcel bitte melde dich!
die “hits” der 90er
malte von spreeblick hat zusammen mit nils bokelberg ne super liste von videos inklusive kommentaren mit hits aus den [tag]90er[/tag]n zusammengestellt. den artikel findet ihr hier: http://www.spreeblick.com/2008/11/12/die-erschreckendsten-hits-der-90er/
alle hab ich noch garnicht geschafft durchzuschauen. aber meine persönliche nr.1 in der liste ist eindeutig “je te donne” von worlds apart.
mfg René
