A classic/common problem... What's your solution?

Hi,
I'm looking for the best solution to a 'problem' that I know many people have come
up against in the J2EE world...
Here's a quick example of the problem:
You have a class (not an EJB), say, "MaintClass" that creates (and holds a reference
to) a Thread that repeated does some work (for example scans a db for a certain entry).
MaintClass also has some methods on it to allow other objects to interigate it and
find out info about what it's up to and/or what results or info it might have available.
You want all classes (servlets/jsps & EJBs) within your J2EE environment to be able
to access a particular instance of this class (it is NOT a singleton) and call methods
on it.
The question is, what is the best way to get this class instantiated one or more
times as the App Server fires up, and where/how do you keep the references to the
instances so that they don't get garbage collected, and so that they can be 'found'
by all all other classes? Also, if you have a 'cluster' of app servers running, you
don't want to have the instances propigate accross the cluster, because there are
threads held by the instances.
Thanks for any suggestions!

Hi
Another approach would be to define a startup method(static)
which will instantiate the "MaintClass". This method can essentially be called by
a startup program which can hold the references of your "MaintClass" and can be delegated
to ejb's or servlets by means of handler methods.
But Michael's suggestion would be a good practise here as we are
dealing with things in the J2EE scenario
Regards
Pradeep
Michael Young <[email protected]> wrote:
Hi.
One approach might be to use a startup class to bind your object to the
JNDI tree. When you
bind to the JNDI tree you have the option to have the reference replicated
across the
cluster, or you can bind a local instance without replication.
HTH,
Michael
Dan wrote:
Hi,
I'm looking for the best solution to a 'problem' that I know many peoplehave come
up against in the J2EE world...
Here's a quick example of the problem:
You have a class (not an EJB), say, "MaintClass" that creates (and holdsa reference
to) a Thread that repeated does some work (for example scans a db fora certain entry).
MaintClass also has some methods on it to allow other objects to interigateit and
find out info about what it's up to and/or what results or info it mighthave available.
You want all classes (servlets/jsps & EJBs) within your J2EE environmentto be able
to access a particular instance of this class (it is NOT a singleton)and call methods
on it.
The question is, what is the best way to get this class instantiated oneor more
times as the App Server fires up, and where/how do you keep the referencesto the
instances so that they don't get garbage collected, and so that they canbe 'found'
by all all other classes? Also, if you have a 'cluster' of app serversrunning, you
don't want to have the instances propigate accross the cluster, becausethere are
threads held by the instances.
Thanks for any suggestions!--
Michael Young
Developer Relations Engineer
BEA Support

Similar Messages

  • In need of a pattern for a common problem - what to instantiate?

    I'm sure this is a common problem with a standard solution (in a form of well known pattern), but I am not aware of one nor do I have any idea how would I Google for it... So, here it goes (exemplified):
    a user is presented with a combo box that enables him to choose what item he wishes to purchase. Depending on his choice, the application is supposed to instantiate an appropriate class that represents the purchased item. So, if the user chooses a book from the combo box, the class Book should be instantiated, if he chooses a comic book, the ComicBook class would be instantiated etc.
    Apart from introducing a naming convention and instantiating the classes through Class.forName(), how would this problem be solved, in a way as generic as possible?
    This is supposed to be used in a Web app, but I hardly believe that's relevant...

    Hmmm... I'm using JSF but it's my first project so I don't really know it's powers.
    I instantiated all classes that will eventually populate the combo box (through reflection) and now I'm trying to find one which of the objects did the user select.
    Would it be a problem for you to give me at least a rough scatch of what I should do?
    I tried it like this:
    in my managed bean:
    public HtmlSelectOneMenu getProductsMenu() {
            //instantiate and populate the list of products (prodlist)
            for (Product p : prodlist){
                optionlist.add(new SelectItem(p, p.getName()));
            final UISelectItems items = new UISelectItems();
            items.setValue(optionlist);
            productsMenu.getChildren().add(items);
            return productsMenu;
        }and in my JSP:
    <h:selectOneMenu binding="#{managedBean.productsMenu}" />but then, in the bean, when I try:
    ((Product)productsMenu.getValue())I get a Class cast exception. it says it can't can't cast String to Product...
    What am I doing wrong?
    Thank you!

  • What is your solution for getting public transportation in map? Actually my iphone is useless for me because it hasn't a public transportation map.

    what is your solution for getting public transportation in map? Actually my iphone is useless for me because it hasn't a public transportation map.

    This has been a huge problem for me too. I was actually late to work yesterday and wanted to throw my phone out the window of the bus that I finally was able to find. I'm new to Portland, so this suddenly missing feature is particularly problematic. It really is so hard to avoid getting angry, I just can't believe they would eliminate a feature that people rely on so heavily. But anger doesn't do any good so I'm trying my hardest to stay calm and figure out an acceptable solution while Apple works to restore this feature - at least I pray to God that that's what they aim to do. Here are the apps that I've been trying, I'll try to explain how they work and maybe they will work for you. This is going to be a long post, but I'm hoping some people will find it helpful.
    I'll start with the most obvious of all - adding Google Maps to your homescreen. Every time you launch the app you will get a diaologue prompting you to allow Google Mpas to use your location, and then you will be in an environment that looks similiar to what we are used to. It does not integrate with your contact list, so one workaround I've been using is going to my contacts and holding my finger on an address to copy it to the clipboard. Be aware that leaving this web app will lose whatever you're looking at and go back to the start, so best to do this before you launch it. You'll notice some strange behavior - for instance the drop down menu of suggested locations will apear and then quickly disaprear, so just ignore this. Often it will often unexpectadly scroll to the top for some reason when you're trying to do something towards the bottom. Haven't figured out a fix except for trying to not get flustered and doing things slowly and deliberately. It's not as quick as we're used to anyway so this is not hard to do. If you'd like to see any of the suggested routes on a map you can do this by clicking the small 'Map View' link. Just be aware that you can only do this once or you will have to type in your starting an ending points again, as there is no way to go back to the list you were just looking at once you are in map view. One thing that I have found helpful about the Google maps method is when looking at a route, whether in list or map view, you can see the stop ID right there, which is helpful if your city has a way to check real-time arrivals. For instance here in Portland you can text this stop ID to a certain number and immediately receive real-time arrivals.
    The app I've been using most is called 'Transit'. It's pretty beautiful aesthetically, and the UI is simpler than anything else I've come across, which is convenient for a task that you want to accomplish as quickly as possible so you can put away your phone and be on your way. When you first launch it you're presented with three bus routes that stop near your current location. It tells you which direction the route is headed and in how many minutes the next bus is scheduled to arrive. This is helpful if you are familiar with that particular busline, otherwise there's no indication of where the line will take you. Upon clicking a line, you're presented with three buttons (again, loving the simplicity). One reverses the direction of that same busline. One expands the list of times so you can quicly see all the arrival times for that bus route at that particular stop for the entire day. The other takes you to map view and quickly displays the location of this stop. And here's the best feature of all (!!), it shows you the busline as a blue line and every single stop is marked with a circle. You can click on a circle and it displays the expected arrival time at that stop. This is all very helpful in some circumstances, but of course it does not let you type in a destination and have it build a route for you, and if you'll be transferring to another line this will not help you at all. To accomplish this you press the arrow in the lower left where you can type in a starting point, ending point, and an arrival/departure time. And this DOES reference your contact list. It will then allow you to quickly switch between three routes that it selects. It also searches Maps (actually it says 'Powered by Foursquare' for landmarks/establishments. For instance if I type in 'sushi', I'm presented with a handful of sushi joints in my area. There is a bug in this app where sometimes the 'Route' button is missing and you can only resolve this by leaving the app and quitting the process in the multitasking trail. When it builds your route, you can click on any point of transfer and it will tell you what time that bus/train is leaving. There is no list view, but personally I never found list view very helpful anyway. I know some people will disagree though.
    Now I'll talk about HopStop. This is a kind of clunky interface unfortunately, and also has ads which I can't stand. It is able to reference your contact list. My least favorite thing about this app is the list it gives you is so excessively long-winded it's hilarious. Every single stop along the route is listed in this list view, so you'll be scrolling through literally dozens of pages of useless information like 'Pass such-and-such - 1 min. Pass such-and-such - 1 min. Pass such and such - 2 min.' Oh well. The good news is on this insanely long list, it indicates when you are supposed to do something other than sit patiently in your seat by having an icon to the left of that instruction - either a person walking or a bus number. When you switch to list view unfortunately it no longer displays departure times, so you'll have to be switching betwen maps and list view. One great feature of this app is it lets you save routes to your favorite list. It also lets you find bus stops and quickly see what bus lines hit those stops. I can't stand the flashing advertisements, so I avoid using this at all costs.
    On to 'City Maps'. Again, the first thing you will see is a short list of bus lines that hit the stop nearest to you. Tap on one and it shows you the next three departures in either direction, as well as the distance between your current location and the stop in question. This app also searches for restaurants and such, but takes this feature on step further. Here when I type in 'sushi' and select a restaurant, I'm brought to a page that links to the Yelp, Foursquare, and Facebook pages associated with it - even has a link that takes you directly to the menu if Foursquare has it. Awesome feature, right?? Tap on 'Map' and it immediately displays the location and an option to build a few routes. It always displays the walking route below the bus lines to give you a sense of how long it would take (even if it's a two hour walk). Clicking on a bus route on this list takes you to list view. Unfortunately this also displays a deluge of pointess turns that only the bus driver need worry about, but it's not as bad as HopStop. There's an optional feature where it can display Google Street View images right in this list view, if you think that could be helpful. With one tap it quickly switches to a very aesthetically pleasig map view. There's an update button that lets you immediately refresh directions, edit starting/ending points, or give it new directions altogether.
    I'm sure in just a moment someone will come along and say something insulting about how we're blowing things out of proportion. I guess that's just the nature of trolls - a lot of people find being angry on forums while hiding behind their screen names cathartic for obvious reasons. Let's all of us just do our best to ignore these people and keep this discussion diplomatic and oriented towards helpful solutions. I know none of us want to give up our beloved iPhones, I'm only considering it as a last resort.

  • Hi Apple! My iphone 4g has restored and I can't retrieve the account. I have tried the password renewal that will be send on my mail but unfortunately my mail has been deactivated also.what is your solution for this kind of cases? This is so unfair.

    Hi Apple! My iphone 4g has restored and I can't retrieve the account. I have tried the password renewal that will be send on my mail but unfortunately my mail has been deactivated also.what is your solution for this kind of cases? This is so unfair.

    http://support.apple.com/kb/HT5312
    If you established a rescue email address, there will be a link on the "Passwords & Security" page of id.apple.com.  Clicking the link will send the reset to your rescue email address (NOTE:  This is not the same address as your Apple ID email)
    If there is no link on the page, then you didn't establish a rescue email address.  Contact AppleCare at 800.694.7466, and ask for account security.  You will need to answer some questions to verify your identity, AND you will need access to a computer to generate a temporary support pin.
    HTH

  • What's your solution to stop crackling problems???? Here's m

    Hi everybody (sorry for my bad english)?I have the Xfi Extrem Music with the A8v Motherboard, Athlon64 4000, 2G? DDR, Sapphire x950 Pro 52.Since the beginning i have crackling problem with my Xfi card. Before i found this solution, i've installed all the latest drivers, but the problem was still remaining. (Putting down the volume don't have any incidence one the crackling pb)The only solution i've found is this one. When i switch on my computer, i press on delete to get into the Bios and after i just save and quit. Then my comput restart?and then i don't have any?crackling problem. Did u find another solution? better than this one?

    Does anybody have any solution??Is my solution the only one to resolve these problems?

  • Imp-00010 problem , WHAT IS THE SOLUTION?

    hi ...
    I TOOK THE OCP COURSE IN ORACLE 10G , I HAVE THE OCPSQL.DMP FILE WHICH MAKE THE SAME TABLES IN THE MATERIAL SO THAT ONE CAN EXCUTE THE CODES IN THE BOOK AND MAKE SURE OF HIS ANSWERS BECAUSE THIS FILE CREATE THE SAME TABLES AND SO ON ... BUT WHEN I IMPORT THE FILE IT MAKE THE ABOVE ERROR AND THE INFORMATION WON'T BE THERE ... PLZ IF ANY ONE CAN FIX THE DAMAGE OR GIVE ME THE SAME FILE I NEED IT ERGENTLY

    first of all thankx for replying , hoek , I will write the code that I paste in sql * , It excuted perfectly but the problem is in the dmp file , the text is
    drop user ocpsql cascade;
    drop role sqlrole;
    create role sqlrole;
    grant alter session to sqlrole;
    grant create session to sqlrole;
    grant create table to sqlrole;
    grant create view to sqlrole;
    grant create sequence to sqlrole;
    grant create synonym to sqlrole;
    grant create procedure to sqlrole;
    grant create trigger to sqlrole;
    grant create type to sqlrole;
    grant query rewrite to sqlrole;
    grant create any index to sqlrole;
    grant create public synonym to sqlrole;
    grant execute on sys.dbms_stats to sqlrole;
    create user ocpsql identified by oracle;
    grant unlimited tablespace to ocpsql;
    grant sqlrole to ocpsql;
    host imp ocpsql/oracle file=c:\ocpsql.dmp log=c:\ocpsql.log

  • CD-DVD ( Optical Drives ) Common Problems and Solutions

    CD/DVD Common Problems…
    Dear friends, I have noticed that many laptop users suffering from some common problems. cd/dvd ( Optical Drive ) problems are one of them.. so here I am trying to collect and make available solutions related to cd/dvd drives . Almost all solutions are already advised in previous posts but these are  all are in one post. We all are here for sharing problems and solutions. I always appreciate all corrections and additions. In first look optical drive problems seems like hardware problem. These problems have hardware/software both possibility so I request to administrator, to make available this post in both ( hardware – software  ) sections. I put only solution links to save forum’s valuable space.
    CD-DVD drive called  an OPTICAL DRIVE.
    CD-DVD discs called A MEDIA
    There are 2 possibilities for optical drives problems.
    Widows based problems
    Hardware based problems
    First here are windows based few common problems
    All windows based solutions are from Microsoft Corporation.
    Your CD drive or DVD drive is missing or is not recognized by Windows or other programs - Windows XP...
    Symptom:Your CD drive or DVD drive is missing or not recognized by Windows or other programs, so you cannot play or access a CD or DVD
    The CD drive or the DVD drive does not work as expected on a computer that you upgraded to Windows V...
    Symptom : You upgrade a computer to Windows Vista or install Windows Vista Service Pack 1 or you install or uninstall applications that have a CD/DVD filter driver.
    When you restart the computer, the CD drive or DVD drive no longer works as expected
    Your CD or DVD drive cannot read or write media
    Symptoms : Your CD or DVD Drive does not read or write and is shown as disabled
    The media in your CD or DVD drive cannot be read
    The media cannot be written to by your CD or DVD drive
    You receive one of the following errors:
    A class specific or device specific driver is missing or corrupt
    A CD or DVD drive cannot be found or is not connected
    The CD or DVD drive is experiencing a problem that prevents it from working properly
    The CD or DVD drive is not accessible via an assigned drive letter
    How to troubleshoot common problems that occur when a Windows XP-based computer cannot read a CD or ...
    Symptoms:
    The disc label does not appear in Windows Explorer.
    The contents of the disc do not appear in Windows Explorer.
    When you insert the disc in the drive or when your computer tries to read the disc,the computer stops responding.
    You cannot eject the disc from the drive.
    The computer takes a long time to read the disc.
    CD drive or DVD drive errors may cause unexpected program crash in Windows XP
    Symptom : Error
    "Program_name has caused and error and must be closed. We apologize for the inconvenience. If you were in the middle of something, the information you were working on might be lost. Please tell Microsoft about this problem. We have created an error report that you can send to help us improve rogram_name. We will treat this report as confidential and anonymous. To see what data this error report contains, click here."
    You cannot write to a DVD-RAM disc that is in a DVD-RAM/CD-RW combination drive
    Symptom : "The disc in the drive is not a writable CD or it is full. Please insert a blank, writable CD into drive D:\, or insert a disc with enough free space to hold all the files you have selected for writing to CD. "
    DVD-RW Drive Appears in My Computer as a DVD-R Drive
    Symptom : "If your computer has a DVD-RW (digital video disc rewritable) optical drive, the DVD-RW icon may not appear in My Computer. Instead, your DVD-RW optical drive may appear as a DVD-R (digital video disc recordable) icon."
    Windows XP does not recognize a DVD-RW disc
    Symptom : When you insert a DVD-RW disc into the DVD drive of a Microsoft Windows XP-based computer, Windows XP does not recognize the disc. For example, you do not see any files on the disc.
    You may also experience this problem with DVD-RW discs that have been formatted as VD-VR. Some consumer DVD recorders use the DVD-VR format.
    CD-R drive or CD-RW drive is not recognized as a recordable device
    Symptom : When you try to burn data to a CD-R or a CD-RW, you do not have the option to send data to the CD drive.
    When you view the properties of the CD-R drive or the CD-RW drive, you notice that the Recording tab is not displayed in the CD Drive (drive_letter: ) Properties dialog box, where drive_letter is the letter of the CD-R drive or CD-RW drive.
    Note To view the CD Drive (drive_letter: ) Properties dialog box, click Start, click My Computer, right-click the CD drive that you want, and then click Properties.
    Additionally, you may receive the following error message:
    There is no disc in the drive. Please insert a writable CD into drive.
    CD-ROM Drive May Not Be Able to Read a UDF-Formatted Disc in Windows XP
    Symptom : Your computer cannot read some or all files on CDs or DVDs that were recorded through the use of the Optical Storage Technology Association (OSTA) Universal Disk Format (UDF) file system standard. Symptoms may include:
    The disc is not recognized at all and shows up as empty.
    Error messages such as "The file or directory is corrupt and unreadable" appear when you try to access files in Windows Explorer.
    Some portions of a DVD-video may not function correctly
    How to troubleshoot issues that occur when you write data to a CD-R or CD-RW optical disc in Windows...
    Symptoms :issues that occur if you write data to CD-R and CD-RW optical discs and how to troubleshoot issues with CD-R and CD-RW drives.
    These are most common issues related to optical drivers.
    Tomorrow will try to explain hardware possibilities.
    All friends suggestions and correction are highly advisable..

    I upgraded to W7 and everything works fine except two things.
    I followed the
    http://h30434.www3.hp.com/t5/Operating-systems-and-software/Windows7-Upgrade-Guide-for-dv6000-dv9000...
    process and still have the problem DVD not under device manager
     DVD spins when booting but after W7 splash screen no longer functions, it did work prior to upgrade.
    I have seen many listed problems but no solution. my device is a TS-L632N and based on the most recent drivers i can find still not working. I looked in the registry and it is not listed under cdrom or
    {4D36E965-E325-11CE-BFC1-08002BE10318}
    there are no upper or lower filters

  • My MacBook Pro with Lion 10.7.2, only audio on the headset, and speaker mute. With Windows, the audio works in speaker and headphone jack. What is the problem? What's the solution?

    My MacBook Pro with Lion 10.7.2, only audio on the headset, and speaker mute. With Windows, the audio works in speaker and headphone jack. What is the problem? What's the solution?

    There is probably a red light on inside your headphone port, indicating that the analog/digital switch in there is stuck in the digital position. Insert a headphone plug and wigle it around, especially in the horizontal plane, as you insert and remove it several times. This will usually unstick the switch and restore normal operation. If it doesn't, the machine will need to be repaired.
    This has been a fairly common problem, but in most cases it is easily cured as described above.

  • What should i do my sleep/wake button on iphone 5 does not work properly it only works if i press on the left side of it and my iphone still on warranty i heard its a common problem

    what should i do my sleep/wake button on iphone 5 does not work properly it only works if i press on the left side of it and my iphone still on warranty i heard its a common problem

    If there's a hardware defect and your phone is under warranty, bring it to Apple for replacement.

  • HT1222 ipad apps 1 I lost all after I installed new windows and I tried to connect it between your computer and iPad, what's the solution? (Please Inbox : Bambangtjio@yahoo.o.id) Thanks

    ipad apps 1 I lost all after I installed new windows and I tried to connect it between your computer and iPad, what's the solution? (Please Inbox : [email protected]) Thanks

    Hi,
    Sounds like it isn't to serious. the Bluetooth connection had an error and that is that generated
    the Problem report.
    When the Blackberry started to use Bluetooth the "gold standard" was using Microsoft's
    "native" windows drivers. Now, every major PC company has there own version
    Thus the problem report.
    There is  rather involved and lengthy procedure to check and install the correct Bluetooth drivers
    in the Dell, but I really don't think you want to take that on.( Nod you head and say H*LL YES)
    Here is what I propose;
    The problem report needs to be resolved or it wont go away. Read the manual, call Dell,
    try apologizing to it and that you'll never never do it again, what ever it takes!
    Make the best investment you can make for your Blackberry, buy a media card.
    All the memory in the BB is dynamic, this facilitates the functions of the phone.
    By storing media in that memory, you effect are wasting X amount for file storage.
    Store all media and files on the media card, and you will have a smooth running device.
    They run about $25.00usd, they are easy to install, and they also make moving your
    media a snap. You will need the USB adapter that came with it, but you can get that at
    your local carrier store.
    So if you agree with this I need some info.
    On the Blackberry go to the options icon,click then scroll up to ABOUT.
    I need your software version number, it's listed in this format: 4.x.x.xxx.
    Send it back to me and I can tell you what size card you can get.
    Let me know your thoughts!
    Thanks,
    Bifocals
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • HT1695 Wi-Fi to your iPhone does not work with the knowledge that I have worked Restart for the same purpose network does not work What is the solution please help as soon as

    Wi-Fi to your iPhone does not work with the knowledge that I have worked Restart for the same purpose network does not work What is the solution please help as soon as

    Okay, the Wi-Fi doesn't work.  Turn it on.
    Beyond that, we cannot offer any other assistance as you've failed to provide useful details of the problem.
    When responding, post in your native language as your English makes very little sense.

  • HT201407 hi, i am from india and i have just replaced my sim card in my iphone 4s but it says that iphone could not be activated because the activation server cannot be reached. what is the solution to attend this problem ?

    hi, i am from india and i have just replaced my sim card in my iphone 4s but it says that iphone could not be activated because the activation server cannot be reached. what is the solution to attend this problem ?

    Hello Sunnymalik1,
    You must only have the required sim. All the information should be on your box.
    ^Connor

  • 'Sorry a serious error has occured that requires Adobe Premiere Pro to shut down. We will attempt to save your current project'. What is the solution? (Mac)

    There is an error that says when I am open my project: 'Sorry a serious error has occured that requires Adobe Premiere Pro to shut down. We will attempt to save your current project'. What is the solution? (mac)

    This happens to me all the time too. When I attempt to reopen, it makes a "copy of" my project. This is frustrating and happiness often.

  • For those with RSD: what is your Problem Description?

    I just got the box by DHL to send my MacBook with RSD to Memphis. On the other side of the shipping label is:
    Problem Description: No Power/No Light.
    This obviously doesn't describe the problem. So, others with RSD that are sending your MacBooks to Memphis: what does your Problem Description say?
    I found an old post (http://discussions.apple.com/thread.jspa?messageID=2889831&#2889831) about this but that was made before this problem became widespread like it is now.

    BOTH BOXES I've received in the last two months (one each for the TWO TIMES I've sent my MB in, once for RSD, second time cause it died completely with 15 minutes of getting it back from the RSD repair) said "No Power/No Light," but through my discussions (many) with AppleCare, they are aware of the actual problem.

  • I buy new ipad but the garranty in my country don't support it,, and now i have a problem in the device,,, what is the solution?

    i buy new ipad but the garranty in my country don't support it,, and now i have a problem in the device,,, what is the solution?

    Take it yourself or send it to friend in country where guarantee supports it.
    Do not try to ship it to Apple - they will not accept international
    shipments nor will they return it to you.
    What is the problem? Maybe someone here can offer some advice to solve
    the problem.

Maybe you are looking for