• Home
  • RSS Feed
  • Log in

J(2)ee, the basics and beyond
Posted by Sander Hautvast at around evening time: June 30th, 2009

In this series I want to address some topics that are old and well known, but still seem to puzzle developers and administrators in a j2ee environment. Think of anything in or around an application server. When talking of application servers I mostly refer to websphere. Sadly I have no real experience using any other. Yet I aim to keep a broad perspective, not to narrow the audience. The level should be beginner to intermediate.

Part1 Starting your own threads.

As long as I worked with application servers, people have always told me not to start my own threads, because the j2ee specification states that this is forbidden. These threads are also referred to as 'naked' and 'unmanaged'. The danger they pose is doing things that the application server knows nothing about. It could cause resource leaks, no debugging, failing to stop a server or security problems.

Yet there is a number of open source frameworks that do just this, and no one seems to object. Think of quartz, or Log4j (the watchdog that monitors changes in log4j settings). And even the jdk itself is guilty: use of java.util.Timer also causes so called unmanaged threads.

And until now the application servers I know haven´t objected either. So applications were actually free to spawn whatever they want and get away with it.

There was also a reason not to change this situation. The way in which it worked made the application dependent on application server internals. In the case of websphere, the method is fully supported by IBM and didn´t change in websphere 6 for instance; yet developers are reluctant to build software that won´t run on other application servers. This certainly makes migration easier.  A disadvantage (of creating your won threads) is that you´re on your own when it comes to transaction management and concurrency control.

The way it worked was:

implement com.ibm.websphere.asynchbeans.Work, obtain a workmanager from jndi and submit the Work class to the manager.

For some time now there is commonj. This is a set of interfaces that have to be implemented by j2ee vendors.
Now you can implement commonj.work.Work, obtain a workmanager from jndi and submit the Work class

The main advantage of this is that commonj can be supported by other application servers. Weblogic 9.0+ does it, geronimo, and sadly no other, until now (afaik). So your application is now only a bit more portable. I think commonj could be made to work with jboss AS. You´d have to implement the workmanager (and other classes) yourself, as an Mbean.

The spring javadoc mentions the lack of official vendor support for commonj with some regret. And I have not been able to find any information about the origins and the future for commonj.
Talking of Spring, they provide a couple of very useful classes that simplify even further the above procedure:

create a org.springframework.scheduling.commonj.WorkManagerTaskExecutor instance, providing a jndi name and submit any Runnable class. You only need commonj on your build path, which is in the spring dependencies.

If you happen to run in websphere 6.1 you´ll have a WorkManager by default using wm/default for the jndi lookup. At lookup a log entry will appear stating that you didn´t use a resource reference. Yet it will all work just fine.

Add the resource reference by putting the next lines in your web.xml


<resource-ref>
   <res-ref-name>wm/WorkManager</res-ref-name>
   <res-type>commonj.work.WorkManager</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

The deployer will have to map this to the actual WorkManager at deploy time.

Spring will add java:comp/env to your jndi name if you set the flag resourceRef to true.

Both commonj and spring also support scheduling of jobs. This could be a safer way than using quartz, especially if your jobs need database access.

Configuring the WorkManager is another thing. Your administrator will have to know how many threads you expect. In Websphere you can also specify if the JAAS subject of the scheduling thread will have to be passed on to the scheduled thread. If disabled, the scheduled thread will have no security context. It will not be able to call EJB´s or other services (unless they do their own login).

The growable property makes the threadpool maximum obsolete and any number of threads can be started. This is all right as long as there are enough resources. It's probably a good setting for finding out the number of threads in certain situations (like under load). Once you´ve established this number, apply it as the maximum for the threadpool and disable growable.

Conclusion

There is no reason to create naked threads. Aapache and two major vendors support commonj. Existing applications and frameworks that run in a j2ee container should be adjusted to at least try to obtain a commonj WorkManager, before resorting to creating threads itself. Spring accomodates for this nicely. Talk to your administrator to sort out the details of the threadpool.

Recomended reading

http://www.devx.com/Java/Article/28815/1763

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/config_wls/self_tuned.html

http://www.devwebsphere.com/devwebsphere/2005/06/async_beans_pro.html

  • Share/Bookmark

Filed under Concurrency Control, Java, Middleware, websphere | 3 Comments »



3 Responses to “J(2)ee, the basics and beyond”



    Wilfred Springer Says:
    Posted at: July 1, 2009 at 8:01 am

    Nice! Are you planning to cover all the programming restrictions in section 21.1.2 of the EJB spec? (Like, how to avoid using java.io, etc.)



    Lars Vonk Says:
    Posted at: July 1, 2009 at 7:07 pm

    Maybe it is better that the JEE servers adjust and provide an implementation of the java.util.concurrent api. Than we could have code that run inside and outside a container. Maybe not all functionality commonj provides is in the concurrent api but the Thread stuff certainly is.



    Sander Hautvast Says:
    Posted at: July 2, 2009 at 8:30 am

    Thanks Lars, I´d immediately opt for a standard jee/j2se solution in favour of commonj. Why not expose a juc Executor?



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (279)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Flex (17)
  • JPA (17)
    • JPA implementation patterns (13)
  • Eclipse (15)
  • Quality Assurance (14)
  • Middleware (19)
  • Frameworks (13)

Tag Cloud

    Poppendieck JavaOne product owner Grails Performance Hibernate Semantic Web qcon Agile Java Functional Programming esb Testing Ajax XML Scala Spring fitnesse Maven Seam Groovy SOA Scrum Closures Xebia Architecture Lean IntelliJ Introduction to Agile Agile Awareness Workshop
medicin depression buy phentermine without a perscription aricept generic hair loss help how do you prevent bone loss urinary tract infection symptoms viagra sex domination cialis viagra cures for throat infection buy sumycin acne care new medication for cancer treatment help for sleeping problems on-line pharmacies cure snoring medications to help clot blood what is aspirin buy zestoretic bronchitis vs pneumonia back pain muscle acne face medication muscle women pain behind knee fat blocker man health arthritis natural cure woman health women insomnia cheap phentermine online cats and irritable bowel syndrome buy cialis generic online nutritional diet for osteoporosis abnormal blood clots treatments for hair loss what is zyprexa dental whitening products impotence herbs drugs for diabetes allergy prevention buy canada levitra Mentax adhd in children hair loss in woman medicines for blood clot online imitrex viagra buy free dog products clindamycin drug how to stop hair loss chloramphenicol discount drug viagra what valium does permanent hair loss heart failure medicine avapro 150mg ordering viagra online food allergies order viagra online online viagra prescription carisoprodol mg improve your skin discount erectile dysfunction medication buy xanax online buy order viagra scabies teatments information allegra vitamine b1 diazepam breast cancer support free stop smoking cipro side effects ultram cheapest treatment attention deficit disorder discount vitamins supplements how to get viagra online synthroid buy cheapest cialis zyrtec online how to clear acne preventive osteoporosis immune stimulants what is hoodia On Line Viagra getting over the pain diflucan dosage health asthma online stores hair loss products blood clot drugs colon parasites hair loss products discount medicine pravastatin buy griseofulvin tablets order indomethacin dog health products how to take a beta-blocker diazapan is valium treating cold sores chronic pain drug what is osteoporosis stress drug tooth whitening lowering cholesterol naturally legality of buying cialis online order levitra treatment for insomnia cheapest cialis index depakote overdose alprazolam condom sales treatment of yeast infection xanax sales taking viagra after cialis how to control pain new birth control chest pain health prozac prescription blood clots viagra in mexico chlamydia pill cancer drugs cold flu drugs how do i order viagra online super viagra acyclovir medicine benadryl dosage erythromycin pregnancy buy contoured condom chronic muscle pain pet health dogs treatment attention deficit disorder dental teeth whitening asthma medicine free prescription drugs herpes drug diabetes treatment buy tooth whitening gel cheap fast valium generic levitra buy cheapest viagra online lopressor drug pharmacy drug prices ultram dosing treatments for bipolar disorder neurontin withdrawal parasite medication chlamydia tips for increasing breast size ways to enhance breast what is valium used for metformin tablet order birth control hair loss for men how does xanax work treatment hepatitis c rythmol cheap acai antioxidants nexium generic blood pressure pills levitra online no prescription Levitra Online medications on line motion sickness drugs bactrim online order roxithromycin nicotine where can i order viagra immune supplements buy erexin v bph prostate allopurinol xanax for depression drug new smoking stop cheap impotence drug generic cialis delivery new treatment for depression antibiotics for cat viagra china alternative medicine cholesterol viagra dose anxiety disorder treatment severe muscle pain treatment of cancer calcium carbonate penis enlargement without pill valium maximum dosage reasons for high blood pressure energy product breast enlargement info cheap effexor building your body wrinkle cream aricept dosage alpha blocker increasing female sex drive valium depression new pain meds no rx xanax drug trileptal mg imitrex avapro 150mg medicine drugs contraception female claritin pill medication for acne med orders buy viagra internet levitra effect treatment for blood clots order sominex buy creatine buy precose cheap viagra overnight lopressor drug body building info health drugs general health and medical what is diazepam eye infections in dogs online prescription pills diclofenac tablet new medication anxiety buy citalopram medication male enhancement enhancement fat blocker medicine for throat infection order cardizem about soma health remedies for dogs generic xanax cheap zyrtec for depression medicine viagra sex domination buy acne skin care product hypnosis help study cure vaginal yeast infection weight loss supplement program muscle pain in leg how to increase erection buy viagra what is cla augmentin doses gaining muscle mass health med online heart rate treatments lopressor drug dog ear canal phentermine without prescription viagra order online weight loss glipizide diabetes astelin generic fat blocker buy gel tooth whitening cheap wellbutrin online weight loss program buy antiox anti-biotics acne skin treatmen tramadole vpxl pill drugs affecting levitra immune system support augmentin hypothyroidism medication buy erexin v uy prescription medication without a prescription buy discount order osteo arthritis online buy pilocarpine cheapest place to buy phentermine parasite treatment impotence help body fat loss viagra herb alternative constipation supplements treatment dementia adhd and medications muscle spasm relief viagra online cheap relieve upper back pain stop hair loss discount viagra online menstrual cycle problems antifungal shampoo side effects ativan gabapentin medication where can i buy viagra diazepam buy soma online clonidine dosage viagra gel top hair loss fast antibiotics cure chlamydia skin fungal infections drug zofran give up smoking alternative medicine cholesterol sleeping help best online viagra scams prednisone 10mg viagra sex domination lotensin easy weight loss pain meds without prescription over the counter drugs new high blood pressure medic generic compazine cetirizine drug order phentermine best fat blockers woman enhancement supplement drug zofran buy precose new drug treatment for cancer how to increase fertility viagra in australia benadryl dosing buy alcoholism medications order l arginine buy diazepam generic for ativan ativan prescription drugs weight loss treatment for chest pain woman health where can i buy phentermine online skin fungal infection give up smoking viagra on line hoodia information how does osteoporosis occur buy viagra online buy alcoholism medications depakote overdose klonopin pill tetracycline capsules what is high blood pressure bladder control for dogs generic for lipitor glucophage online pharmacy gabapentin dosage treating yeast infections dog health info cymbalta anxiety cheap tramadol without prescription hydrea drugs used for cancer cure for high blood pressure alcohol and valium relief from constipation liver infection treatment cialis soft zantac medication help sleep problems all natural antibiotics order medication without prescription sleep problems free hypnotherapy gaining muscle mass cheap viagra order online natural help for pain how to buy viagra drug price celebrex information otc diuretic levitra 10 mg buy medicine online pets products relief foot pain cialis without prescription med care cheapest generic cialis rapid hair loss pain medications generic side effects meds without prescriptions cat anxiety buy simplicef natural cure arthritis effects of high blood pressure lowest price generic viagra how to get birth control new breast cancer drug buy topamax blood pressure meds when are beta blockers prescribed how to get pain meds order fosamax online viagra name order viagra viagra cialis cat's eye health how to relieve lower back pain treating ear infections diazapan is valium online pain doctors high blood pressure in elderly medication to stop smoking wellbutrin dosages diabetes blood sugar levels weight loss diet pill side effects of prescribed pain pills drug list high blood pressure buy cialis online in usa ultram cost how to help osteoporosis how to use clomid discount brand viagra wellbutrin cymbalta buy pills without a prescription buy pain medicine online tab tramadol depression symptoms treatment how levitra work hypertension medications beta blockers prevent premature ejaculation xanax interactions with other medicines purchase medicine on line does alli work xenical mexico prescriptions buy sumycin uy prescription medication without a prescription ambien cost methocarbamol effects cheap beta blockers cats bladder reduce cholesterol naturally metformin tablet scabies medicine breast enhancer pills body building over 50 order viagra cheap zestril medication how to buy prescription medications online pharma kamagra drugs depression ear infection symptoms big muscle controlling blood pressure pain meds and pregnancy buy diazepam without prescription skin allergies antibiotic zoloft buy weight loss nutrition program Buy Cialis breast increase meds without prescriptions blood clots medical edema treatment for flu best hangover remedy diabetes drugs