Creating a "context" for an application...or something like that

hey all. I've got a console program that runs all the time, on a TimerTask. What I would like to do is create objects in the main class and have those objects available to other classes and threads generated by the stuff the TimerTask's thread creates, but without passing objects around. Sort of like one would do with servlet/jsp programming with contexts and the request scope and such.
I come from a web background, and so I think about this very much like a "scope" thing, where objects can be created and put in the request scope, and then other objects can avail themselves of stuff in the request scope.
What i'm really trying to do is create a DB Connection pool in the main class and have threads and such use the connections, but i don't want to pass the pool object around to all the different objects within the TimerTask's thread. But this is more a question of scoping or availability of objects than it is about DBCP, per se.
I feel like I should have learned this stuff in java 101 way back when, but I didn't, or I forgot, and now i need to gitterdone.
Any tips? Thanks os much.

hey all. I've got a console program that runs all
the time, on a TimerTask. What I would like to do is
create objects in the main class and have those
objects available to other classes and threads
generated by the stuff the TimerTask's thread
creates, but without passing objects around. Sort of
like one would do with servlet/jsp programming with
contexts and the request scope and such.In fact, with servlets and JSPs, the objects are passed around via a ServletConfig object (the servlet's public void init(ServletConfig config) method) for the application (ServletContext) scope. The request scope of course is passed along to the service methods in the ServletRequest object, as is the HttpSession scope. The PageContext is generated in a JSP at the beginning of the _jspService method...
But anyway, that is not what you need to do... If you want one context that the whole application can use, you can create a Singleton class, and use a static method from the class (of a Factory Object) to generate the Context/pass around the already generated Context. Take a www.google.com search for Singleton and you should see what I mean. But, since you will be working with multiple threads, make sure you sinchronise your methods...
I come from a web background, and so I think about
this very much like a "scope" thing, where objects
can be created and put in the request scope, and then
other objects can avail themselves of stuff in the
request scope.If you want more than one Context, then that is a bit more difficult. What I would do is have some sort of TaskFactory that generates your classes (Tasks) that run in the Timer. Follow the Servlet example of having a TaskConfig object that will hold a reference to the single ApplicationContext that all tasks share, then generates a new TaskContext that will serve individual threads. Pass this TaskConfig object into each of your class's init(...) methods. (Maybe have an AbstractTask that has an init(TaskConfig ) method that stores it in a protected class variable so each individual Task doesn't have to worry about it - like the GenericServlet does...)
What i'm really trying to do is create a DB
Connection pool in the main class and have threads
and such use the connections, but i don't want to
pass the pool object around to all the different
objects within the TimerTask's thread. I think this is usually done with a Singlton, I could be wrong though... I beleive a search through the forums for Connection Pooling may provide some examples...
But this is
more a question of scoping or availability of objects
than it is about DBCP, per se.
I feel like I should have learned this stuff in java
101 way back when, but I didn't, or I forgot, and now
i need to gitterdone.
Any tips? Thanks os much.

Similar Messages

  • My iPhone 4 no longer connects to my car or alarm clock after a recent sync to my computer.  The message at I get when trying to. Connect is "this accessory is not optimized for the device" or something like that.  Anyone know how to fix this?

    My iPhone 4 no longer connects to my car or alarm clock after a recent sync to my computer.  The message at I get when trying to. Connect is "this accessory is not optimized for the device" or something like that.  Anyone know how to fix this?

    Hello there philp_69,
    If I understand correctly it sounds like your phone hasnt been recognized in iTunes on your PC since the last couple of updates. I would use the troubleshooting in the following article which will walk you through the steps one by one. 
    iPhone, iPad, or iPod touch not recognized in iTunes for Windows
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Hi I need to setup my email account  on my ipad2 coz I deleted, accidentalli it ask me for a server os something like that can u help me please

    Hi I need to setup my email account  on my ipad2 coz I deleted, accidentalli it ask me for a server os something like that can u help me please

    I'm from Kuwait and there is no technical support for our hope I find a solution to have

  • App Loader tell me "No New found for this device" or something like that

    I've been going around and around with this issue - I know that in addition to the DM, I need tohave the OS installed on my laptop. So, I've installed, uninstalled, etc.., etc, deleted teh Vendor xml. pulled the battery and put it back in - still get the message - So, I've bought software, unzipped it into a folder, and the app loader still doesn't "see" the .alx file.
    Any ideas?????
    Solved!
    Go to Solution.

    Have you got  your app loader pointed to the right directory (where you saved the .alx file)
    Hope this helps!
    I just reread your post. Are you updating to a new OS?
    What software did you buy? A third party app?
    Message Edited by Bifocals on 08-01-2008 06:00 PM
    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.

  • I want to create home page for my application with short URL

    I want to create home page for my application with short URL
    as when I want user to use my application user must go to URL like this
    http://127.0.0.1:7101/My-Project/faces/app/empModule/allEmployees/viewMyEmployees.jspxI want the user to use short URL , How can I use shorter URL not all this one.
    I want shorter URL for my application not to write full path .
    thanks in advance.
    Edited by: user611775 on Oct 31, 2010 10:21 PM

    Well,
    it's up to you. The first part (Mcit-Project-ViewController-context-root) is the context root which you define in the view controller project. 'faces' is the name the servlet filter reacts on. You can't omit it but shorten it in web.xml. The rest is your directory structure. I'm not sure how to shorten this other as to move the jspx files back into the web root folder.
    By the way an ADF faces app never uses the .jspx at the end of the url. If you specify '.jspx', you only render the page but don't start the work flow.
    Timo

  • I'm wondering if there is any way to view the results of the form other than in a spreadsheet?  Is it possible to print responses one by one in PDF format, or word, etc?  I'd like to create a form for proposal applications, and the spreadsheet format resu

    I'm wondering if there is any way to view the results of the form other than in a table?  Is it possible to print responses one by one in PDF format, or word, etc?  I'd like to create a form for proposal applications, and the spreadsheet format results are nearly unusable for this type of form.

    Hi Nalani500 ,
    Yes, you can print the response in a PDF by following the steps suggested below.
    1) Go to the response file
    2) Select the response you want to print
    3) Click on Save as PDF button and it would save the selected response in PDF format.
    Thanks,
    Vikrantt Singh

  • Apple should do something for the equipment stolen something like block and only activated by key words given to register the device on the apple's website

    Apple should do something for the equipment stolen something like block it(them) and only activated by key words given to register the device on the apple's website

    Tell Apple:
    http://www.apple.com/feedback
    Doubtful that this would happen.  Privacy laws would likely be tested with this.
    No manufacturer does this.

  • How to create sql query for item master with operator LIKE with variables?

    hi all,
    How to create sql query for item master with
    operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
    Jeyakanthan

    Hi Jeyakanthan,
    here is an example (put the like statement into the where field)
    SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
    The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
    Regards Steffen

  • I am trying to create a signature for my emails. The box that asksto 'choose a signature' won't allow me to. Any suggestions?

    I am trying to create a signature for my emails. The box that asks to 'choose a signature' won't allow me to. Any suggestions?

    It's ok, I got it sorted :-)

  • I just updated my pages and now it won't load. This is on my iPad. The first version which has the latest version it can have 5.1 or something like that. I am trying to open a document and am worried that if I uninstall and reinstall I will lose all my do

    I just updated my pages and now it won't load. This is on my iPad. The first version which has the latest version it can have 5.1 or something like that. I am trying to open a document and am worried that if I uninstall and reinstall I will lose all my documents

    I just uninstalled it and am waiting for it to reinstall. I sincerely hope that I have not lost everything that I worked on so hard. Now that mobile me is gone, I have not been able to go between devices to transfer things. I was merely trying to take a document I had worked on and open it in pages, but it said my version was too old. When I updated, it wouldn't load. Now I cannot do anything. I hope that the reinstall fixes it without losing everything. Please advise!!! Yes, I am in panic mode.

  • I ran a virus/trojan fix and this is what it said it could not repair something in the main library core or something like that.  What do I do?  The problem seems to be with safari?

    I ran a virus/trojan fix and this is what it said it could not repair something in the main library core or something like that.  What do I do?  The problem seems to be with safari?

    I ran the utility disk and this is what it said.
    Warning permission differ Applications/Safari drwxr-xrx they are -rwxr-xr system/livrary Cores has been modified and will not be repaired.
    Permission apllication differ on System/livrary/Pr or could be -rw-r--r-- they are rwxr-xr-x Application/iTune be droxr-xr-x they are rwxr-xr-x
    Then I hit fix permissions and it said this
    Warning SUID file Systm/Library/Core has been modified will not be repaired
    I also downloaded Bitdefender Virus Scanner and it found nothing.

  • My ipod touch 1st gen has gone into recovery and wont restore because of a error 1 or something like that can someone help me quick this ipod is my little cousins and i dont want her mum to find out what happend

    my ipod touch 1st gen has gone into recovery and wont restore because of a error 1 or something like that can someone help me quick this ipod is my little cousins and i dont want her mum to find out what happend

    I have not seen a solution for error (1)
    make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • Hi everybody, my Macbook air mid 2012 MD 231 suddenly shut down then i can not turn it on. I heard a sound like a fuse is blown or something like that. Did any system break or burnt? I did not charge at that moment. Plz help

    my Macbook air mid 2012 suddenly turn off after a strange sound (like the sound òf a fuse has blown or something like that) and I also feel a burnt smell too while i am watching a film on the internet and did not charge the laptop at this moment. The sound was from the left of it, and now just a dark screen , even I tried charging it (still has green light at the charge tool). I bought it on 13st April 2013, not often use.
    I love apple and i am so sad that a new product which i seldom use could be break so easily and outstanding. It's so late in my country now but i am too disappoint about the trouble so i am writing with hope of supporting from Apple and the community.
    Please help , thank bro

    You will have to take it to an Apple Store for repair.

  • Can i charge my MacBook Pro during the airplane time because battery's life is 3 hours only? so is there any cable or something like that? Thanks in advance

    Greetings
    i have a question regarding my MacBook Pro laptop regarding charging it during the airplane time because in fact my battery's life is 3-4 hours, no more,
    so is there any cable or something like that to recharge on the plane? if not, please till me advices to save power for long life battery?
    Kind regargs
    Thanks in advance
    Kerollus Abdelnour

    To keep track of the battery charge and condition go to Apple Menu/System Preferences/EnergySaver and check the show battery status in menu bar.

  • How to lock transaction using function module or something like that

    Hi, all
    I'd like to know the way to lock transacitons using function module or something like that.
    I know this would be possible if calling transaciton SM01, but I want to know other ways like calling function module  (BAPI ) or method.
    Thank you for your cooperation In advance.
    Regards,
    Hideki Kozai

    Hi,
           Try the following FM
    BRF_NETWORK_GRAPHICS           BRF: Network Graphics for BRF Objects
    BRF_INITIALIZE_GRAPHICS_NGR    BRF: Initialize Network Graphics
    BRF_NETWORK_GRAPHICS_NGR       BRF: Network Graphics: Start
    BUSG                           SAP Business Graphics
    GRAPH_2D                       Calling up the 2D business graphics
    GRAPH_2D_MENUE                 DO NOT USE (use 'GRAPH_2D' and 'GRAPH_BUSG_MENU_SET')
    GRAPH_3D                       Calling up the 3D presentation graphics
    GRAPH_BUSG_COLOR_SET           Definition of color pallets for business graphics
    GRAPH_BUSG_MENU_SET            Pushbutton menu (tool bar) for all BUSG modules
    GRAPH_MATRIX                   Calling up SAP Business Graphics (2D, 3D and 4D)
    GRAPH_MATRIX_2D                Calling up the 2D graphics (user-friendly version)
    GRAPH_MATRIX_3D                Structure of 3D graphics (user-friendly version)
    GRAPH_MATRIX_4D                Calling up a 3D graphic (4th dimension stacked representation)
    Regards,

Maybe you are looking for