Home > Java, JavaOne > JavaOne day two

JavaOne day two

General Session

The general session started by some hip-hop/rap group singing and dancing on the stage. I am not very much into rap but I guess most of the people found it amusing.

Next James Gosling went on the stage throwing some t-shirts around using a sling!

Unfortunately I didn’t manage to get any, hopefully next time.

The real session started by announcing the number one rule of the J1; “don’t be shy”. Even if you think a question is stupid there are several other people in the same room who want to ask the same question.

Then they started talking about the Java chips they have installed in our passes. Each pass is actually a JavaCard. There are sensors installed everywhere in the Moscone centre so every time we enter a room it senses where the attendants are going. All our badges are RFID (Radio Frequency Identidication) enabled. Due to this Sun has developed a very smart system to identify the sessions. (Note: you have to pre-register for sessions otherwise you run the risk of missing the sessions). They have devices that read information from the JavaCard before you enter a session room. If the information matches the room then you can enter, otherwise you have to wait in the queue for an available seat.

The Java runtime and the JavaCard are installed in many systems in the world, they are in London’s Oyster card, they even run Istanbul’s transport system.

At this point they showed the JavaOne Open Possibilities video

After these they presented a JavaFX demo that takes data from sensors and displays it on the screen. They measured all the energy used in the general session room (they actually measured the carbon dioxide generated from everybody). These same devices are also used in Tokyo to measure all the energy needed to operate the elevators.

Richard Green went on stage and explained how the JavaFX technology will prevail. traditionally there used to be monolithic and cumbersome systems; think for example an airline application where you have the old terminals with green screens. Only few people knew how to operate them. today the world is changed and things are completely different. You have better GUI, more reusable and user friendly with dynamic actions. People can actually choose their seats, select their type of meal etc. Sun has realised that people need simple, intuitive and compelling interfaces and it’s working on this direction.

Years ago the printing press was an amazing revolution. The sense of using a book was unique. Now you can get interactive books off the internet.

Ian Freed from amazon went into the stage and started presenting the kindle. Years ago the printing press was an amazing revolution. The sense of using a book was unique. Now things have changed and you can get interactive books off the internet. Kindle lets you do that. It does whatever a real book does and also goes beyond the book. You can have all the books you need, newspapers, articles, journals, even blog inside a kindle. Kindle also provides you with recommendations and everything else you can do with the amazon web site. And it uses Java to do all these.

According to Ian Java was selected for kindle for two main reasons; it has a huge developer base/community so it was easy to implement and install the software, and it was easy to emulate the application on a desktop PC before kindle came out and then deploy or keep developing on it when it was released.

Next one on the stage was Rikko Sakaguchi, SVP Sony Ericsson, that talked about how Java helped them quadruple their growth in the past six years. They run Java on their mobile devices. Actually Java is their core strategy since it is the key factor behind their success. They chose Java because of the rich user experience and its portability, it runs everywhere.

Richard Green talked again about RIA and how you can create all these applications. In the traditional model each one of us used to be and do everything, the designer, the developer, everything. But we have moved from the green screen model to compelling designs. We want agility and the right tools to make all the small parts come together. Everything is about the number of iterations, implementations, tests, and evaluations per unit time. This is critical because creating all these is taking too long. Now it’s minimised. Small teams and small groups of people are coming together and building and extending on the work of others.

Next it was the turn of Nandini Ramani to get on the stage. She showed a demo of Connected Life. Connected Life unifies all parts of your favourite applications in one application. She tried to show how to use Connected Life but unfortunately the demo crashed After a quick restart the demo went smoothly and she showed us how you can integrate and embed applications (twitter, flickr, facebook etc) into Connected Life. And every single bit of Connected Life is written in JavaFX.

A very interesting feature is that the application can be dragged out of the browser and onto the desktop. She tried to do that but unfortunately the demo crashed for one more time. Then there was a demonstration of the same application on a mobile phone. It looked and behaved exactly the same as long as the phone had the capability of supporting it. Then Nandini and Richard tried to get a picture and use it with the demo but unfortunately it crashed for one more time. Pitty because I really liked the demo.

A flickr demo written in JavaFX followed. This demo was about how you can write an application that fetches pictures from flickr based on given tags. This demo showed how easy it is to implement application that utilise high performance audio and 3D movement rendering. Interesting thing is that when the tag “jamesgosling” was entered, flickr returned the picture we I had taken with Paris and James Gosling! So me and Paris were famous for a few minutes since twelve thousand people were looking at us. The five minutes of fame as Woody Allen put it 🙂

Next in line was a JavaFX demo (the same Connected Life application) using an android emulator. This showed the power of JavaFX. It unifies everything that’s shipping in a common runtime. It brings all the devices together under a common umbrella.

JavaFX also brings a new advertising model. It gives developers a two-way conversation with their audiences.

Note also that all current video players that support blue ray already run Java. And since Richard thinks that blue ray will prevail Java has already prevailed.

Now time for some numbers

  • First taste of JavaFX is coming in July
  • JavaFX 1.0 will ship in Fall 2008
  • JavaFX mobile will ship in Spring 2009
  • Glassfish’s kernel is 98K. It loads in one second. Glassfish follows a modular design, it uses modules that build around the kernel.
  • Glassfish downloads went up
  • Mysql has 65.000 downloads per day (50.000 before it was acquired by Sun)
  • Netbeans has 44% growth year after year with regards to active users
  • 48.000.000 JRE downloads per month
  • Java now ships with Ubuntu and Red Hat.

Next in line was project hydrazine. Hydrazine is a project for content creators. It can help you find, merge, deploy and share services. It allows you to bring services together and make them available to everyone interested in using them.

Jonathan Swartz went on the stage next. He said that there is battle for the next development platform. Sun is ready and has four fundamental differentiating activities in mind;

  • they want to reach more devices on the planet
  • they have to make the platform compelling for developers (fast, high performance, accessible to developers and accessible to consumers)
  • they are placing a stake on the ground (Java will give an insight to the developers about the users of this content, understand who is using it and how they are using it, they have to understand the users if they are to build a subsidised application)
  • it’s all going to be free (freely available, free price, free philosophically)

Next it was Neil Young (yes it was actually Neil Young himself).

Neil wanted to bring to the world everything he has done in the past years. He wanted to make his music available to vast audiences. Originally the digital sound wasn’t good enough but now with the blue ray tachnology you can get far better sound. Neil needed a technology that was flexible, could be dropped anywhere in the time line and have a representation of music of this time. He chose Java for this.

At this point a very realistic demo application was shown that could play Neil’s music from archives on a blue ray disk. The GUI was amazing and very easy to use. You could navigate to sounds, pictures and video and you could play all of them (you could actually see vinyl records playing when the music was playing). It made it look very real. Neil wanted to do it back in the ’90s but you couldn’t do that with the DVD. They were defeated by the technology back then but now the technology has progessed they were able to do it using blue ray and Java.

If you need more information about this project have a look at Neil Young archives.

Lastly there was a slide about openeco.

Designing a MMORPG with project Darkstar

This session was presented by Jeffrey Kesselman.

As an avid gamer I wanted to attend the project darkstar session. Project darkstar is a platform that help you write Massively Multiplayer Online Games (MMOG). Strictly speaking online games today are not massive, but the potential audience is as it can grow exponentially. The big advantage of MMOG is that they allow players to engage in content from a variety of locations and devices (desktop PCs, mobile devices, set top boxes etc).

It takes anything between 20 and 30 million in order to develop a good MMOG and this is what keeps the industry away from growing. When you spend that much money you don’t want to take many and big risks; you want to use things that are already tried and tested, things that are already successful.

Project darkstar is open source under the GPL license and is completely free. All you need to do is to buy a boxcha, install darkstar, stick it to your system and you are ready to go.

Sun game Server (SGS) wants to solve the problems corporations are encounter when developing MMO games. They want to make practical and scalable on-line game content in a host-able model (to enable better games with more and smaller groups of developers), and to change the current state of MMO which exhibits limited persistence and fault tolerance.

The purpose of SGS is to make distributable persistent and fault-tolerant game servers which are easy and economical to administer. Corporations do not have to spend vast amounts of code in order to operate game servers any more.

They also want to make server side code reliable for the developer and to present a simple single-threaded event-driven programming model. The developer should never have his code fail due to interactions between code handling different events.

For the operator they aim at a single point of administration and easy load balancing across the entire data centre.

SGS in the design is much like a 3-tier architecture.

Tier 1 is the communications tier that takes care of peer to peer or publish and subscribe channels.
it defines a pluggable transport, reliable/unreliable or ordered/unordered byte package transport and it’s optimised for the lowest worst time latency.

Tier 2 is the execution kernel, it executes tasks in response to events and it is analogous to a J2EE application server. It is stateless and tasks appear to be single-threaded. It is also optimised for the optimised for lowest worst case scenario.

Tier 3 is the object store; it stores objects. It’s lightning fast, highly scalable and analogous to database layer. It is built to scale and all application state lives here, in an in memory data-store with secondary storage backup. It’s transactional and fault tolerant but it’s not relational. If a deadlock happens at tier 2 it is detected here. It’s also optimised for the lowest worst case latencies.

SGS supports two kinds of events; system and manager events. Systems events generated from method calls like initialise() and loggedin() which are generated by the project darkstar infrastructure. Manager events are generated by darkstar managers, (managers are pluggable additions to the infrastructure, they are like drivers). All the events result in a task being queued for execution and all of them have a listener interface associated with them.

A task is a threaded execution and a transactional (ACID) context. Task execution appears to be single-threaded (but in reality it isn’t). Tasks aqcuire read and write locks on game objects and can abort and reschedule if a conflict occurs. Tasks scale out horizontally over the back end but this is not a detail we need to think about, just remember that fewer object access conflicts results in a greater scalability.

Task execution is mostly unordered and parallel. However relative task ordering for a single user’s input is assured (actions get executed in the order they arrive at the server and an event generated by the user won’t start processing until all processing of earlier events have successfully completed. So we can say that the input is assured), and also parent-child task ordering is assured (a task may use the TaskManager to queue child tasks and a child task won’t start processing until its parent has finished).

SGS Managers; they present an API to the application and they generate events. There are three standard (visible) managers

  • task manager
  • data manager
  • communications manager

Managers are really just facades. They are there to provide services to other services.

Applications are made of ManagedObjects, they (the ManagedObjects)

  • live in the object store
  • they are fetched and locked by tasks
  • are written back at successful termination of event
  • they are seemingly single-thread in execution
  • they are referenced through ManagedReferences
  • are normal Java objects

ManagedReferences are coming from the DataManager.

There are two types of communication; client/server (direct communication, client sends commands, server responds) and communication channels.

At that point there was an exampel of how to implement a sample game (DarkMMO). Before any MMO implementation we have to consider technical challenges (set design limits, consider results of latency spikes. Another consideration is how to deal with lag. do we respond locally immediately and check results with server for correctness later? Or do we allow others to lag on the screen?).

Consider scaling issues early enough in the design process. Set design limits, n-squared is the enemy (take the game world and divide it to pieces so the world is zoned. Each zone is tile-based and we can limit awareness to size of one tile).

ManagedObjects can be defined as the entities in a game. Entities that can be identified are players (represent a user’s account), characters (they can interact with the environment), monsters, NPCs, placeable objects (they don’t move around but they can be moved by players or monsters), walkways etc. In order to map these entities to event classes such as ManagedObject, ClientSessionListener or Task should be used.

When the space is partitioned and the use/monsters move, large structures must be searchedon every possible position that is changed and must be frequently modified

In order to grid the zone the cell size should be equal to the maximum view distance (what can’t be seen does not matter) and the character should see at most 4 surrounding cells at a time

Other issues we might encounter are the differences positions in combat. The exact position doesn’t really matter but the range does (the distance between players can be different on different screens), During fight we have two possible cases; hand to hand and ranged combat

With hand to hand combat we have a fixed close range, if the server decides that the attacker is at close range then it can lock the defender in place, move the attacker to within melee combat and start the fight. Bt we might encounter issue here is we have obstacles or traps (a possible solution would be to auto-detect them and abort attack).

In ranged combat viewers can’t tell the exact distance but as long as the server thinks target is in range it can allow allow attack. The server should be able to check blocking

DarkMud (demo with artwork from NeverWinter nights). the quality is not very good bu tthis is the best I could do

Project SunSPOT: a Java technology enabled platform for ubiquitous programming

This session was presented mainly by Vipul Gupta and Arshan Poursohi.

SunSPOTs are devices that have a sensor attached and can be used to measure several things. A distinct characteristic of SunSPOTS are that they are self-healing when they are in a network. If one node is lost then the system can recognise it and recalculate the shortest path.

They are felxible (all Java software stack) and there is also access to the internet through the base SunSPOT or through an HTTP proxy.

An integral part is the strong security. Since SunSPOTs communicate in a wireless manner data nac be stolen by third parties. SunSPOTs use efficient cryptography with simple user-transparent key management (the use elliptic curve cryptography).

The code is deployed securely. A Java project is compiled into a Jar file and then deployed to suite. Due to limited capabilities SunSPOT only verifies the digital signature of the Jar file and not the bytecode itself.

Each user’s SDK has a public/private key. SunSPOT stores “trusted” key of owner and compares it with it’s own key. It sends the public key back to the user, user signs the key and sends it back to the SunSPOT. SunSPOT matches it with the private key (this all happens transparently from the user). SunSPOT uses SSL with HTTPS support for web communication.

Then Randy Smith presented Solarium and demonstrated how it can be used with SunSPOTs by having two SunSPOTs communicate with each other.

Ron Goldman talked about how one can emulate SunSPOTs. SunSPOTs are not cheap, they cost money. Since they cannot give SunSPOTs away for free Sun has developed an emulator that behaves exactly like a SunSPOT. For exampel virtual SunSPOTs can send radio messages to each other, or use a sensor panel. One can use Solarium to create a virtual SunSPOT and control it from there.

Arshan Poursohi talked about SunSPOT advantages; the capable hardware that makes prototyping very easy. Then he talked about Sun’s Blackbox project.

Sun has also developed an outreach programme granting SunSPOTs to students and educators worldwide and also it participates in larger programmes to reach out to university and professors

Yggdrasil, another project in Brazil

For more information visit sunspotworld.


How reliable is the emulator? Can I make sure 100% that an application on the emulator will work the same on the real device? Yes

Can I do internet connection? Yes, as long as there is a spot box connected to the station. There is communication through the USB connection.

Who owns the SunSPOT API? It’s under a GPL license. If you modify it you have to redistribute it. Any new applications developed are own by the developers.

How sun is making money from SunSPOTs? By promoting Java and by the data generated by these devices and they need to process this data. Sun is very good at that.

JavaScript programming language: the language everybody loves to hate

In the past I have tried hard, very hard, to like JavaScript but to no avail. This time I said to myself that I will attend a JavaScript session, maybe I was wrong and I need to give it a n-th chance. I also thought maybe I could get ideas in order to use a scripting language at work. Unfortunately not even this time I managed to like it.

The session started with Roberto Chinnici announcing that if you do a search on google with “(x) sucks” it will return 625000 results, the highest of all programming languages/scripts. But I want to be fair and objective and I will describe the session from the notes I took.

Roberto said that JavaScript was frozen too soon and came with a punchy standard library. This gave JavaScript a bad name that continues until now.

JavaScript in reality is a functional programming language. Functions are first class objects, they are closures. Functions can be anonymous and can be of a higher order. They are also “first class functions” meaning that it’s quite normal to pass around functions and return functions from within other functions. For example

function compose(f, g)
  return function (z)
    return f(g(z));

Closures are capturing variables in their environment

function createCounter()
  var i=o;
  return function()
    return i+1;

Although JavaScript provides several features from other modern languages there is a catch with variable declaration. There are no warning for multiple variable definition. So if you define a variable and then redefine it later in the script (it does not matter in what scope the variable is defined into) JavaScript does not actually warn you and ignores completely the oldest defining variable.

If you need a good library to use with javaScript have a look at the functional library (http://osteele.com/sources/javascript/functional/)

In JavaScript there is no tail recursion and this runs a very serious risk of blowing the stack. Also the runtime is not particularly optimised for heavy use of HOF (High Order Functions). But more sophisticated compilers are on their way

In OO JavaScript technology objects

  • exist on their own account
  • have a bunch of named properties
  • (almost) every one of them has a prototype
  • prototype from chains
  • property lookups follow prototype chain
  • Object.prototype is the default “root” (Object.prototype.prototype = undefined)
  • this is a special variable, like arguments

The secret not to go wrong with objects is to forget about constructor and classical inheritance and use Douglas Cockford’s object function instead. Object by all accounts should have been a primitive but it isn’t and you need to build chains of object using supporting creation functions.

Defective Java code: turning WTF code into a learning experience

William Pugh started by showing some code from the daily WTF.

char c = (char) inputStream.read();
 if (c == -1)

But the exact same code can be found in several other implementations, in sun.net.httpserver.ChunkedInputStream, in org.eclipse.jdt.core.dom.CharacterLiteral, in org.eclipse.pde.internal.core.content.BundleManifestDescriber and many more.

The above code will fail. It will fail because char is the only unsigned primitive data type and therefore it’s value will never be -1. Also casting an int to a char will only work for ASCII characters, not for unicode. So the moral of the story is

  • methods that return -1 for EOF can be tricky (you need to check for -1 bfore doing anythign with the result)
  • code is rarely tested for unexpected EOF (you may need to use a mocking framework)
  • don’t assume that any mistake is so unique that no one else could have made it.

Second WTF was the following code (found in Jetty-6.1.3 BoundedThreadPool)

private final String lock = “LOCK”;

The catch here is that String constants are interned and shared in the JVM. So if you want to synchronise do it on a raw object.

Another WTF code is the following

private Long myLong = new Long(0);

  Long l = myLong.longValue();
  myLong = new Long(l.longValue());

The above code does not provide a mutual exclusion. One thread can synchronise on an old value, another thread on a newer value, and both be in a critical region at the same time. This could result in duplicated values being handed out. Long objects aren’t shared, but you need a “remove explicit autoboxing” quick fix.

The key mistake here is that one tried to synchronise on a field (Long in our example). This is something that cannot be done, you can only synchronise on an object.

The next example was about synchronisation on a getClass() method call (example taken from java.awt.Panel in JDK version 1.6.0).

String constructComponentName()
    return base + nameCounter++;

This is a mistake since subclasses can synchronise on something else. The best way to ensure synchronisation is to use an AtomicInteger or synchronise on Panel.class. never synchronise on getClass(). In general it’s good to follow the following guidelines

  • do not think about what to synchronise on
  • instead, think about who to synchronise with
  • avoid synchronising on something that unrelated code can synchronise on

Next example was the following code


protected final class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException
  throw new IOException(“method resolveClass not supported”);

In the code above Class extends java.io.ObjectInputStream and by calling the resolveClass method it works the same as in the OIS class.

The solution is to be found at the following code


protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {...}


protected final Class resolveClass(ObjectStreamClass v) throws IOException, ClassNoFoundException {...}

Notice that


import com.sun.corba.se.impl.io.ObjectStreamClass<orange colour>;

protected final Class resolveClass(ObjectStreamClass<orange colour> v) throws IOException, ClassNoFoundException {...}

The parameter types are different: they have the same simple name but they belong to different packages. The protected final Class method does not override method in the superclass.

The moral is

  • @Override is your friend. do an autofix to apply it uniformly throughout your code base. if you don’t see it somewhere it should appear, something is wrong
  • Minimise overloading simple names. Autocompletion makes it far too easy to get the wrong one.
  • Avoid overloading the simple name of a superclass. If you have a class alpha.Foobar do not define a subclass beta.FooBar. There are too many possibilities for collisions.

Formatting a date


protected static final DateFormat DATE_FORMAT...

return new Day(Day.DATE_FORMAT.parse(s));

The catch here is that DateFormat is not thread safe. It stores the date to be formatted/parsed into an internal field. If two threads try to simultaneously parse or format the date you may get runtime exceptions or incorrectly formatted date. This is not just a theoretical possibility; it’s easy to replicate with test code and has happened in the past causing field failures (this was actually reported to FindBugs by someone who was bitten by this bug).

The moral is

  • DateFormat (and subtypes) are not thread safe
  • Immutability is your friend
  • When designing an API understand your use cases. If the class feels like an immutable constant, people will use it like an immutable constant, even if the JavaDoc tool says not to.

Last code sample had to do with equality


public boolean equals(java.lang.Object ts)
  if (ts instanceof Timestamp)
    return this.equals((Timestamp)ts);
    return false;

The requirements for equals are

  • equals(null) returns false
  • if x.equals(y) then x.hashCode() == y.hashCode()
  • equals is reflexive, symmetric and transitive

Date d = new Date();
Timestamp ts = new Timestamp(d.getTime());
System.out.println(d.equals(ts)); // true
System.out.println(ts.equals(d)); // false

The difference in the equals method above is because equals() is not symmetric. If you ask Date if it’s equal to a Timestamp it will return true. Date looks at the the value of the class and compares it with the Timestamp value. It is the same so Date and Timestamp are equal. If you ask Timestamp if it is equal to Date, then it will return false, since the compared object to Timestamp is not a Timestamp.

Symmetry is important

  • a primary use of equals() methods is in containers (e.g. Sets of Maps)
  • various methods might invoke equals as a.equals(b) or b.equals(a)
  • non-symmetric equals can produce confusing and hard to reproduce results

There is also the equals debate; should equals use instanceof or getClass() to check for compatible arguments?

If you use instanceof and override the equals method, you may break symmetry. If you use getClass(), it is impossible to define a subclass such that instances could be equal to an instance of the base class.

This leads to the conclusion that it is hard to design a subtype and the equals issue only matters when implementing a class that is designed to be subclassed. Doing so is hard in general, even more so when you anticipate third parties extending the class. Specifying how equals should behave is only of one many tricky decisions you will have to make.

As Doug Lea put it more than 20 years ago “the problem with defining equals as class method is that there are too many senses of equals for one method to support. and the author of a class won’t have all of them in mind”.

We have for instance object equality (no two distinct objects are equal, this is the definition inherited from the Object class and its useful and sufficient more often than you would expect). We also have value equality (any two objects that represent the same value should be equal. For exampel a LinkedList and an ArrayList that represent the values 1,2,3 should be equal). And we have behaviour equality where objects are equal if you can’t distinguish them based on their behaviour.

Using getClass() generally implies behavioural equality. But it’s the behavioural equality that is the most subtle, and to some confusing or just wrong. How can for example B be a subclass of A if it’s impossible for B to be equal to an A? With getClass() any extension of a class splits the equality relation, even an extension to add some performance monitoring.

Hibernate uses a lot the getClass() equality because it creates proxy classes for persistent object model classes. The use of getClass() causes errors and there are lots of discussions about it in the hibernate forums.

But getClass() is sometimes used in an abstract base class to compare any common fields of the class. An example of such implementation is in the java.security.basicPermission class.

On the other hand if you use instanceof and override equals in a subclasses

  • you must not change the semantics of equals
  • the only thing you are allowed to do is to use a more efficient algorithm, or instrument for debugging or performing monitoring

The moral is

  • document your equals semantics
  • if you use instanceof consider declaring the equals method final
  • using getClass() avoids the finality of the equals method but limits the behaviours you can implement

Most of the learning opportunities come from students as they tend to be very good mstake generators. And more often that you expect the mistakes made by students produce detectors that find mistakes in production code (although often manifested in different ways and for different reasons).

What’s new for concurrency on the Java platform standard edition

All features discussed in this session by Brian Goetz will be available in Java 7. Brian started by saying that as of about 2003 we stopped seeing increases in CPU clock rate. But Moore’s law still holds strong since now we have more cores per chip rather than faster cores. As a result many more programmers become concurrent programmers (maybe reluctantly). We should expect core count to increase exponentially for at least the next ten years.

Hardware trends drive software trends. Hardware shapes language, library and framework design. Java had support since day one, but it was mainly asynchrony, not concurrency (which was right for the hardware of the day). The revolution was with JDK5 that offers coarse-grained concurrency.

Lets say we have a database query. A fine-grained parallelism will parse and analyse the query, will plan a selection and will try to find ways to minimise processing power in the shortest time. CPU intensive jobs are sped up with parallelism.

Select maximum example (find the largest number in a list). In Java5 we can use a thread pool and divide the array, then assign each division to each thread in the pool. Put them in a collection of tasks, start the tasks and wait till they are completely. Then iterate through all of them and pick up the largest. But this undesirable because some of the sub tasks might completely earlier than the others (in this case you have a processor that does not do any work). The bigger problem though is that the code can be ugly and clunky (as the find maximum code is duplicated).

Solution: divide and conquer. Bring the problem down to tiny sub-problems. Then solve the sub-problems and combine the results. The invoke in parallel step waits for both halves to complete before providing the combination result.

For fork-join use the RecursiveAction class in the fork-jion framework is ideal for representing divide and conquer solutions. this can run in a single or a thousand CPU system, it won’t make any difference. Fork-join offers a portable way to express many parallel algorithms since the code is independent of the execution topology. But we still need to set a number of fork-join threads in the pool.

Under the hood we are not using an ordinary thread pool, nor an Executor. We are looking for a solution to minimise contention and overhead. The technique fork-join uses is called work stealing. You have a pool of worker thread (each worker has its own double-ended work queue) and pushes new tasks to its own queue. Then reads it from the head of the queue. If a queue is empty then a worker tries to get a task from the tail of another queue.

Stealing is infrequent since worker put and read tasks in their queue in a LIFO order and the size of work items gets smaller as problem is divided. Therefore you get a very nice work balancing with no central co-ordination. You start by giving the tasks to a central worker and it keeps dividing them. Eventually all the workers have something to do with minimum synchronisation cost.

Extend LinkedAsynchAction instead of RecursiveAction. It manages and maintains a parent-child relationship and finished methods mean “wait for all my children to be finished”.

Fork-join can be used for several things like matrix operations, numerical integration, finite-element modelling, game playing (move generation, move evaluation, alpha-beta pruning) etc.

ParallelArray classes let you declaratively specify aggregate operation on data arrays. There are version of primitives and objects ParallelArray<T>. Coding a “select-maximum” with ParallelArray is trivial as all you have to do it

ParallelLongArray pa…

ParallelArray framework automates fork-join decomposition for operations on arrays and it can use filtering and mapping. There are a few restrictions though. Filtering has to precede mapping, mapping has to precede aggregation.

Basic operations supported by ParallelArray are

  • filtering (selecting subsets of the elements)
  • mapping (convert selected elements to another form)
  • replacement (create a new PA derived from the original)
  • aggregation (combine all values into a single value), application (perform an action for each selected element).

You can combine multiple ParallelArrays. The PA has combiners for arithmetic operations like max, min etc.

There is also connection with closures. We can specify the work to do with a closure passed to the methods of the ParallelArrays. With closures the Api can be rewritten in terms of functional types instead of named types, Ops.Predicate<T> becomes {T=> boolean}

JUG community BOF; JUG leaders from around the world interact with Sun

Three JUG leaders discussed their concerns with people from Sun and other JUG leaders.

Frank Greco set three main concerns

  • Java’s buzz factor is declining. What is sun doing to increase sex appeal?
  • JEE and app servers are legacy. What is the next step for Java on the server that will scale with less complexity?
  • Jini/javaspaces are enjoying a resurgence in financial applications and with scale hungry web 2.0. Why does sun ignore these technologies?

Antonio Concalves

  • Java is too complex and is becoming legacy. Many other simpler languages are running on the JVM. Is the JVM the only feature of Java?
  • The JCP should be seen as a community not as an opaque ruling organisation. Open up the JCP
  • More exposure should be given to the JUGs. What about a booth at JavaOne.

Paul Webber

  • New features vs backward compatibility
  • Desktop vs web programming (complexity, tooling APIs). What progress is being made with the Java media API?
  • Jug sustainability. What is important to the local JUG community?

There were several opinions and thoughts about the concerns. Sun replied that whatever a JUG leader needs in order to start a JUG and get it going can be found by asking for Sun;s help or visiting the java.net web site.

Some answers to the questions above were

  • Java hype is not declining. If you look at J1, Javoxx, javabin, Jfall you will see that Java hype is far from declining.
  • Java 7 will address the issues with multi-core threading.

More questions and concerns raised

  • Issues we face is that trying to educate people that Java has changed. Many people learned Java years ago but now it has changed.
  • What language we should be using; it’s matter if preferences and how each language is solving a particular problem.
  • What is missing is intercommunication among jug leaders.
  • We need to get the messages across that Java is not slow because people who do not know consider it slow and this has its drawbacks.
  • How does Java handle middle age? How do we increase the value of the Java community?
  • What can we do in order to make Java more attractive?

We know in general what developers are doing with the technology. We have a view of how things are working around the world. If you move to South Asia or Africa Java is used as a fit all solution. Most companies that do not use Java (like Facebook), they use the language they were grown with when they were students. If they don’t use Java now they will never do.

Categories: Java, JavaOne
  1. 7 May 2008 at 12:10 pm

    Pano you are right dude! I dont think Java is decling! I dont like JUG leaders…saying that..I mean it is..sort of..obscure!

    Man I need to be there 😛

  2. 7 May 2008 at 4:43 pm

    Hehe, you should have seen me. I wanted to say more. I also wanted to say that application servers ar far from dead (just look at the work ads in UK or in Belgium) but we didn’t have time. And yes, you are right, you definetely need to be here. Next time we should come together 🙂

  1. 7 May 2008 at 10:27 am
  2. 7 May 2008 at 3:09 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: