Wednesday, May 2, 2007

Java <-> HTML

Have Java code, put it some where on a web page, that looks good and nice as it looks in an IDE. So do it all you need is Java to HTML converter. There are tons available on the net, but that didn't stop me from writing my own.

A console based JavaHTMLConvertor is ready. Now just have to decorate it with some GUI to make is user friendly. It's on the incubator and I should be able to bake it tomorrow ;) and it will be available for download.
Code snippet is available at :

http://javaticks.googlepages.com/threadPool.html


There is a mistake in the above program, which tries to interrupt all the other thread in pool on emergency shutdown. This is not possible. A thread can only interrupt itself and not other threads.

A sample Thread Pool implementation..

Many jobs at a time, but no so many!

We have many thread pool implementations available in Java, but still I would like to create my own, just to understand the concepts and here I am to share that experience with you all..

Before we start coding, let us first think about the requirement of a thread pool.

1. We have a pool of thread (may be on demand or not). The no. of threads in a pool is fixed. say 5 or 10.
2. We add jobs to the pool.
3. If any thread is free in the pool, then it would jump in and take up the job.
4. If there are no free threads in pool (that means all the threads are working), the job will be waiting to be handled by some thread, which becomes available after completing the current job.

That's it. Problem at hand is simple, we just need to code that's it...!!

ZZZzzzz.. (3 hours past)

argh..! code is ready for the post. But I have a big problem. I don't want to just copy and paste my java code, it looks dirty.. So I want to convert my Java to HTML so that I can put it here. So I searched the net and found many. Then I thought, why don't I write my own? It's going to be very nice to do it. So I decided to save the post as a draft, and continue it once Java to HTML tool kit is ready..

Note: For those who think, how do I then posted formatted java code in Previous post, what I usually used to do is, go to http://forums.sun.com and write the code using code format tag, then click preview and then copy and paste it over here! that's it.. But this time that doesn't work (because of a bug in the HTML formatting in sun website).