Some of you may remember a time when the world of multithreaded programming was limited to a small set of C or C++ applications. Often the threads were used sparingly and restricted to a specific task or computation or even operating system.
When the Java platform arrived it brought with it the ability for anyone to write a fully multithreading program, including those with very little experience in using threads. Even the vendors who had the foresight to implement a threading library in the OS found they needed to fix those libraries in order to let these new multithreaded Java programs run.
The original Java threading model had very basic controls. Synchronized methods and blocks were there to guard code and a wait and notify pattern provided limited conditional support. Things were even more confusing when you had a thread start method but the suspend, resume, and stop counterparts were all deprecated! It wasn't too surprising that talks, books, and articles about using Java threads soon became very popular.
One book in particular stood out, partly due to the title but primarily because of the ideas it contained. That book was Concurrent Programming in Java: Design Principles and Patterns by Doug Lea (Addison-Wesley). This book was different because it looked at designing true concurrent, multithreaded programs first, and then applying that to the Java platform. In the process it uncovered areas where the Java APIs were limited. Instead of forcing developers to work around this restriction, Doug created the Java concurrency API library - a library that provided higher-level thread controls, a complement of locks, and finer-grained synchronization tools.
Fast forward to J2SE 5.0, which should be final by the time you read this. I'm pleased to report that the Java concurrency library is now part of the Java platform. Does that mean you should go back and rework every single piece of threaded code you wrote over the last eight years? Not necessarily. However, if you are starting from scratch or refactoring some historically tricky threading code, I would recommend spending a little time checking out what this library has to offer.
Along with synchronization controls like semaphores and explicit calls to create, set, and release locks, there is a significant upgrade to the thread controls. This new functionality is provided by the ThreadExecutor class. You're probably very aware that when you create a runnable task, there is no mechanism to return a result, throw an exception to the parent, or even cancel that task. Where before you may have used a Runnable task, you can now create a Callable one instead. They're very similar; the following is a small example to show how easy this is.
Here is my runnable task, called Worker. In the Callable version all I have to do is describe my return type, in this example a string, and use the new declaration of Callable that has one method named call instead of run. Notice that with Generics we can explicitly declare the return type so it can be checked at compile time.
class Worker implements Callable<String> {
public String call() {
System.out.println("New Worker");
return "return result";
}
}
To use my task I just need to pick an ExecutorService. In this example I chose the cached thread pool, which will create as many threads as I need but will reuse previously constructed threads if available. The logic behind this is that thread creation can be an expensive operation on some systems.
I create my Callable task, called task, and then create a handle to that task, a Future, that I have named result. The Future task serves two purposes. The first is that I can cancel the task by calling the method result.cancel(true). The true argument means that it's okay to try to cancel an already running task. The second benefit is that it's used to hold the return result. To gain access to the return result, I simply had to call the method result.get().
ExecutorService es = Executors.newCachedThreadPool();
Callable<String> task = new Worker();
Future<String> result;
result=es.submit (task);
try {
System.out.println(result.get());
}catch(Exception e){}
This small example enabled me to use a cached thread pool to hand off tasks, check their status, and cancel them if required. As I mentioned earlier, I used an ExecutorService that declares some convenient default implementations. The concurrency library has a full set of interfaces and many other implementations that you can use. I encourage you to check the library out along with the other J2SE 5.0 features.
About Calvin Austin A section editor of JDJ since June 2004, Calvin Austin is an engineer at SpikeSource.com. He previously led the J2SE 5.0 release at Sun Microsystems and also led Sun's Java on Linux port.
Zafar wrote: 2 years on, and at least where I am living people understand the power of java, and are using it! The world''s biggest oil company has a java initiative! long live netbeans, long live j2se/j2ee 1.4x, long live, tomcat! Thanks to .net technology people here are finally beginning to understand the value of java, and are dropping .net for java.
Emerson Lopes wrote: What's your problem? Are you blind? Have you forgot about how slow java client apps are? Java almost disappear because its weakness on client side. App server has created a new world of opportunities for Java. I'm working now in three new huge projects using Websphere App Server and there is a lot more coming. I almost had no work using applets technologies or client side Java related technologies, just server-side.
Nate Scott wrote: Java? What a pathetic waste of time language. An alternative for developers who weren't smart enough to learn C and C++ from the beginning. Java was the dummy's way out. With twenty-five years of software development experience ranging from Assembly to C++ and more, I have absolutely no sympathy for Sun or its language that is basically used by disgruntled Microsoft haters. Simply put and said again, Microsoft just built a better mouse trap and...it came with cheese.
Dan wrote: To Brian Kiser,
We have law in this country, law that protect the competive enviroment. Microsoft like anyone else has to abide by those law. If people dont like the laws here move
Hash wrote: There are way too many frog in the well who cant and will not see what is outside of MicroSoft. Well ya I know it take a bit to think than to use a cliche like 'Survival of the fittest'.
Wondering: have you tried to buy a brand name computer offlate (like a dell) that will give u an option not to buy MS. Oh no.. that cant happen, cause they know whats best for us, right ??
Fauss Hull wrote: TRUE. It's not Bill Gates fault he's competitive, however, once a company gets monopoly power, the only way to allow competition to continue IS through anti-trust laws.
MicroSoft would not exist as we know it today (or at all) if the US government had not prosecuted IBM in the 70's for anti competetive behavior under the anti-trust laws. At that time IBM was also killing all of the competition by doing just what MicroSoft does today. Not allowing software from other vendors to run on their machines (unless it didn't make lots of money) etc.
As a result of this anti-trust suite, IBM allowed this 'little man' Bill Gates the right to sell DOS. Bill ran with that gift from the government and we see where he is today.
Ok, he made it big, no BIGGER than BIG, but now its time for the government to limit his monopoly power and promote more free competition of good ideas in the softwar...
ArtPerez wrote: Esta es una lista de cuestiones que creo son realidades, no necesariamente lo son, pero para un sector amplio probablemente lo sea y deberan ser tomadas en cuenta para seguir adelante en nuestra are :
-En el mundo de la aplicacion desktop (standalone, fatclient-server) que es el campo de aplicaciones de software comerciales mas amplio sin duda alguna, Java no tiene un peso significativo, y con la tendencia actual tendra muchos problemas para crecer o definitivamente no crecera.
Sun no deberia de manejar el lenguaje Java, aparentemente la mayor parte de los desarrolladores de Java desearian que el manejo del lenguaje fuera abierto y mas desligado de Sun. Aparentemente, el problema principal de Sun para java es microsoft. Otros lenguajes no tienen este problema, de lo cual podemos deducir que tampoco deberia de serlo para Java, y lo cual nos lleva a inferir que Sun tiene otros objet...
Iman Mayes wrote: The LAST thing I want is for the Government (the same one pushing UCITA, RIAA, etc) to force any company to put a competitor's product into theirs. This sets a BAD precedent, and is not a remedy to the problem of utilizing monopolistic practices. What the government should do is force Microsoft to allow OEM's to add whatever they want to Windows, and punish them for any monopolistic practices in the past and going forward. Unfortunately, the all mighty US Court systems folded to the all mighty Microsoft-dollar. But, thats another story.
LaloCeli wrote: You obviously do not know much about J2EE. You can set up a 100% J2EE compliant environment/system with only the money for the hardware, as everything else is free, including the Application Server, the Database, etc. I know it because I have done it.
Try doing that with MicroSoft.
I like MicroSoft, I believe they deserve their place in history, as well as a sector of the industry, and I still do projects in MS environments when the need demands, but don't make claims about things that you don't know enough about.
wrote: "Java get the chance to succeed that Microsoft intentionally and illegally took away."
I think that Java is doing quite well, and will continue to do so. Because of Java, and of course UNIX, we have replaced all our NT/2000 servers for Sun, and Linux servers. No more C++ under Windows, it mostly Java.
How can you say that MicroSoft has taken anything from Java?? Do you know something that we don't? Did you leavve anything out?
I think that the complaining about MicroSoft has to stop, and lets continue coding in Java.
M. Celi
A. Rowley wrote: Has everyone forgotten stability. I have worked in IT for years and used MS and UNIX, Solaris, iPlanet, jsp, java in th eearly days and I spent way to much time getting paged at night to fix MS stuff. Solaris, iPlanet and java rule... All of our ecommerce java app run high speed and any thing we deploy to the web just simply stays running. MS crashes, get viruses etc. The best choice is Unix and java not MS and .net. or anything MS makes. They keep changing them to make you buy them again and agian, like a junky on drugs.
R. Peterson wrote: It should be intuitively obvious, even to the most casual observer, that Java is "open", which means that it is interoperable, portable, and scalable. And, that none of Microsoft's stuff is any of the above.
Al Hembd wrote: Dear all,
There are some posters above who are entirely missing the boat. Microsoft, in using Java, had to sign the agreement that everyone signs when one downloads the Sun JRE. Namely, 1) to ask Sun's permission before changing any of the code, 2) to make known, via open source, to the whole world, what your changes to the platform were; and
3) most important of all, to ask Sun's permission before using Java commercially.
Let's not forget: Sun has the COPYRIGHT on Java. One must sign a copyright agreement before using it as a product. Microsoft clearly and unquestionably violated copyright/patent law in this whole matter.
I would invite the readers to go download again the SDK for Java 1.4. Right before the download, read the terms of the agreement. If you read them, you will find, plain as day, that Microsoft broke the law.
Just being rich is no excuse for Microsoft...
Stephen Bennett wrote: IMHO:
We should all look to a bright future.
As a technology Java has a future. Do not lets any mistakes made in the past or mistakes made in any economic arena fudge you perception of what this technology offers.
As a Sun marketing campaign might say, Go forth and multiple!
Any marketing machine knows: Quickly learn from and then forget mistakes, always look good regardless of the situation.
Thus, Microsoft may not be as solid as we may believe and when one examines the technologies they offer this is clearly the case. They do however show a united and positive front when they are questioned, and, the MS machinery can learn very quickly.
Java and all that goes with it on the other hand has a more troubled pass and future. Primarily due to the fact that it is a more open technology, a technology for the people you might say. Therefore it is reasonable to expect that it w...
Hiring Manager wrote: Guys for my part, I work for a big financial company. We used to be a Microsoft shop with 60+ VB and C++ programmers.
In the last five years we have slowly moved towards J2EE and Java on client side. With a 1000% increase in business we now have 30+ Java/J2EE programmers and are still able to efficiently provide highest uality of services to tyhe finacial professionals in the firm.
We are never hiring another M$, VB programmer again. You will be nits not to have Java / J2EE, Solaris and Linux on your resume and look for a job.
Michael H wrote: I've worked on projects that have built large client GUI's using Swing.
Fat-client Java is dead on the because Swing is too clunky. Compraed to other approaches, it's too difficult to acheive a GUI that is both full featured and efficient.
The Java language is a great advance on C++ as practical language for team development. But it was a very tall ask to design a good set of general purpose libraries. Over time Sun has improved many areas of the libraries and they are great for much of the server-side stuff (but I don't buy into J2EE 100% because it too is rather clunky, but improving).
Swing lacks STANDARD higher level abstractions that would make building business GUI's less tedious. It provides a level of abstraction necessary to build browsers, word-processors or spreadsheets, but most of us aren't coding at this level of abstraction. The layering of abstractions is e...
Ken wrote: JBoss is J2EE, very nice and free.
Don't know if Java is dead or not, but I
get more interest in my Java experience
then in any other. Java has now (IMO)
surpassed C and C++
I have yet to have anyone ask about VB,
C# or .net This is very subjective, but
I'm sticking with Java. You'd be nuts
not to learn Java comming out of college
today.
Fred Barrett wrote: Coming from a developer perspective, I can get a project done faster and easier in Microsoft's dev environments than any Java IDE. As a systems integrator with deadlines and deliverables, until the Java IDEs start helping the process, Microsoft simply has a better product...whatever the Courts say won't change that for me.
What could be a problem with logging in SOA in the presence of such wonderful tools like log4j, Java’s logging library and similar? Why might we need something special for SOA and why aren’t existing techniques enough? The answer is simple and complex simultaneously – in SO...
Aonix released PERC Ultra 5.1 cross development and target support on Sysgo's PikeOS 2.2 real-time operating system. PERC Ultra support of the PikeOS POSIX PSE52 profile provides a solution for the increasing need for portability across multiple operating systems as industries su...
What's the key to team and individual developer productivity in maintaining and extending a large application? Let’s start by making the following assertions: A developer's knowledge of an application code base is likely the single biggest factor of individual productivity. Cor...
An applet, a Java program that runs in a browser, often has to access the client resources. However, the security manager prevents an applet from accessing client resources. To access client resources, the applet has to have the proper permission. With this permission the applet ...
Three-letter acronyms (TLAs) are hardly new in Information Technology: EAI, ESB, SOA, BPM, BAM, ETL, MDM; the list goes on and on. This article is about yet another three-letter acronym, EDA, which stands for Event-Driven Architecture. EDA is not a brand new technology, but rathe...
Furthering its dedication to providing Java developers productivity with choice, Oracle announced the Oracle Enterprise Pack for Eclipse, a new component of Oracle Fusion Middleware. This release marks the first free Eclipse 3.4 environment to support Oracle WebLogic Server 10g R...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice: