Using Timer and TimerTask classes in EJB's(J2EE)

Does J2EE allow us to use Timer and TimerTask classes from java.util package in SessionBean EJB's ( Statless or Statefull )?.
If J2EE does allow, I am not sure how things work in practical, Lets take simple example where a stateless SessionBean creates a Timer class
and schedules a task to be executed after 5 hours and returns. Assuming
GC kicks in many times in 5 hours, I wonder if the Timer object created by survives the GC run's so that it can execute the scheduled tasks.
My gut feeling says that the Timer Object will not survive.. Just
want to confirm that.
I will be interested to know If there are any techiniques that can make
the usage of Timer and TimeTask classes in EJB's possible as well as reliable with minmum impact on over all performance.

Have a look at J2EE 1.4. I think they add a timer service for EJBs there...
Kai

Similar Messages

  • How to Use Pattern and Matcher class.

    HI Guys,
    I am just trying to use Pattern and Matcher classes for my requirement.
    My requirement is :- It should allow the numbers from 1-7 followed by a comma(,) again followed by the numbers from
    1-7. For example:- 1,2,3,4,5 or 3,6,1 or 7,1,3 something like that.
    But it should not allow 0,8 and 9. And also it should not allow any Alphabets and special characters except comma(,).
    I have written some thing like..
    Pattern p = Pattern.compile("([1-7])+([\\,])?([1-7])?");
    Is there any problem with this pattern ??
    Please help out..
    I am new to pattern matching concept..
    Thanks and regards
    Sudheer

    ok guys, this is how my code looks like..
    class  PatternTest
         public static void main(String[] args)
              System.out.println("Hello World!");
              String input = args[0];
              Pattern p = Pattern.compile("([1-7]{1},?)+");
              Matcher m = p.matcher(input);
              if(m.find()) {
                   System.out.println("Pattern Found");
              } else {
                   System.out.println("Invalid pattern");
    }if I enter 8,1,3 its accepting and saying Pattern Found..
    Please correct me if I am wrong.
    Actually this is the test code I am presenting here.. I original requirement is..I will be uploading an excel sheets containg 10 columns and n rows.
    In one of my column, I need to test whether the data in that column is between 1-7 or not..If I get a value consisting of numbers other than 1-7..Then I should
    display him the msg..
    Thanks and regards
    Sudheer

  • Lexical search using Pattern and Matcher class

    Hi Folks,
    Need some help with the following Query. I want to find out how I can implement
    the following by using Pattern / Matcher classes.
    I have a query that returns the following set of strings,
    aa
    abc
    def
    ghi
    glk
    gmonalaks
    golskalskdkdkd
    lkaldkdldldkdld
    mladlad
    n33ieler
    What I would like do is to find out any string that starts with g and Lexical occurs after ghi. So this will return
    ghi / glk / gmonalaks / golskalskdkdkd
    How can I accomplish the above, by using the following two classes.
    Pattern datePattern = Pattern.compile();
    Matcher dateMatcher = datePattern.matcher();
    Thanks a bunch...
    _Shoe Maker..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Nothing in your specification requires a regex. Loop though the strings until you find the string "ghi". Then continue looping though the strings outputting those where the first characters is 'g' .

  • How to use interface and abstract class in the real time sennario ?

    how to validate password and reenter password fields in the struts through the xml files?

    Here is a modified dealForm.jsp that merges the 2 steps - both symbol submission and Yahoo convert is done by it. Play with it and add your DB code to it:
    <html>
    <head><title>IPIB Database Selection</title></head>
    <body bgcolor="#DFDFFF">
    <H1><CENTER>IPIB Database Selection</CENTER></H1>
    <font size=4>
    <%@ page language="java" %>
    <%@ page import="java.net.*,java.io.*,java.util.*" %>
    <%
    String symbol = request.getParameter("symbol");
    if (symbol != null) {
    String urlString = "http://finance.yahoo.com/download/javasoft.beans?SYMBOLS=" + symbol + "&format=ab";
    try {
    URL url = new URL(urlString);
    URLConnection con = url.openConnection();
    InputStream is = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();
    StringTokenizer tokenizer = new StringTokenizer(line,",");
    String name = tokenizer.nextToken();
    name = name.substring(1, name.length()-2);
    String price = tokenizer.nextToken();
    price = price.substring(1, price.length()-2);
    %>
    <p>
    Original line from yahoo <%= line %>
    </p> <p>
    Name: <%= name %>
    </p> <p>
    Price: <%= price %>
    </p> <p>
    Pub DB processing code from dealLoad.jsp here
    </p>
    <%
    } catch (IOException exception) {
    System.err.println("IOException: " + exception);
    } else { %>
    <form action="dealForm.jsp"method="GET">
    <p>Enter Symbol: <input size="20" name="symbol">
    <inputtype="submit" value="Submit">
    </p></form>
    <% } %>
    </font>
    </body>
    </html>

  • What is the difference of using JavaBean and regular classes?

    Experts,
    I am new to JavaBean(not EJB), and wondering what is the difference of using JavaBean for JSP page compared with using regular Java class?
    I know there are Bean tags which save some lines, what else?
    What does "serialization" mean compared with "not serializable"?
    thanks very much.

    No.
    A JavaBean is a regular JavaClass that:
    1) implements java.io.Serializable
    2) Its data members are private, and its data is accessed via getters and setters. You must define the getters and setters. Getters retrive the property, and must be in the format:
    public PropertyType getPropertyName()
    for most cases. The exception is when the PropertyType is a boolean, in which case you use:
    public boolean isPropertyName()
    Setters assign values to the property, and are in the form:
    public void setPropertyName(PropertyType propValue)
    3) There is also a PropertyChangeEvent model that needs to be followed.
    A marker interface has no methods you need to implement. It just marks the class as supporting certain operations. In the case of Serializable, it means the class can be written to be an ObjectOutputStream for persistant storage.
    As far as an example of JavaBean persistance, take a search on the java.sun.com site for Serializeable
    Also, take a look at this: http://java.sun.com/developer/onlineTraining/Beans/beans02/
    It concentrates mainly on gui component beans, but not all beans need to be gui parts... There are other pages to look at, but I can't find them at the moment, and I have to run...

  • Update Unbounded element using SOAP_CLIENT and JAXB classes

    I am writing a custom worklist application using 10.1.3.3. I am able to successfully kick off my BPEL process from my Java application and I am even able to modify most of the fields defined in my XSD. My problem occurs when I try to update the unbounded elements. They are of complex type and each request can have an unlimited number of these elements.
    I used JDeveloper's tool to generate the JAXB classes I'm using to interact and modify the payload of my task. I know that JAXB does not generate setter methods for unbounded elements. I should be able to get the list of elements and simply add to it. Unfortunately, the new list elements are not being saved when I marshall my payload and update the task with the new payload.
    Any ideas on what I'm doing wrong or if there is another way to do this? I've posted code snippets below.
    Thanks!
    Quote Element from XSD:
    <xsd:element name="Quote" nillable="true" minOccurs="0" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="WorksheetId" type="xsd:int" minOccurs="0"/>
    <xsd:element name="QuoteId" type="xsd:int" minOccurs="0"/>
    <xsd:element name="Description" nillable="true" minOccurs="0">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="250"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Quantity" type="xsd:int" nillable="true" minOccurs="0"/>
    <xsd:element name="UnitPrice" type="xsd:float" nillable="true" minOccurs="0"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    AddQuote java code:
    JAXBContext jc = JAXBContext.newInstance("myproject.xml");
    Unmarshaller u = jc.createUnmarshaller();
    Task detailTask = wfSvcClient.getTaskQueryService().getTaskDetailsById(ctx, thisId);
    Element detailPayload = detailTask.getPayloadAsElement();
    ObjectFactory objFactory = new ObjectFactory();
    XMLWorksheet xRequest = objFactory.createWorksheet();
    xRequest = (XMLWorksheet)u.unmarshal(detailPayload.getFirstChild());
    List quotes = xRequest.getQuote();
    quotes.add(quote);
    Marshaller m = jc.createMarshaller();
    m.marshal(xRequest, detailPayload);
    detailTask.setPayloadAsElement(detailPayload);
    taskService.updateTask(ctx, detailTask);

    who actually managed to make the SOAP_CLIENT working ?
    What is the jar list and order you use ?
    Does it work with java 5 ?
    Thanks for the help!

  • Using Time and Date to create calender events

    Hi all,
    I want to create 'events' in a users calender through my apex app. To get just the date seems fine, but ideally I want to store both the Date and time of the event.
    I have a data entry page that has 2 calender items(one item is a date picker, the other item is a modified datepicker that only displays time).
    My idea is to somehow concatenate the 2 values together and insert those into one date column.
    I was wondering if anyone has a elegant solution to this, surely I cant be the first person to come across this?
    Thankyou

    I've tried creating a procedure that to_chars the two date items then concatenates them and to_dates them into the final date item, but this doesnt seem to be working very nicely....

  • Using Timer and Alarm functions with headphones

    I would like to use the timer/alarm in a library setting to help me study. Even though I have my headphones connected properly (i.e. music only plays through the headphones) the timer/alarm notifications are coming through the external speaker. I can't find a way to adjust this. Am I missing something? Please help me stop getting dirty looks in the library. Thanks!

    I just tried that. the calender alarm only goes off in the ear phones. But I am trying to work in intervals of 30mins work 10mins off, which would be a pain to fill my calendar with. At the moment, I am resorting to using the stop watch function. Thanks for the suggestion

  • How to access SOAP message using JAXP and SOAP class?

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder b = factory.newDocumentBuilder();
    FileInputStream fr = new FileInputStream(args[1]);
    Document doc = b.parse(fr);
    Envelope msgEnv = Envelope.unmarshall (doc.getDocumentElement()); <---
    the exception raised:
    java.lang.IllegalArgumentException: Root element of a SOAP message must be: 'htt
    p://schemas.xmlsoap.org/soap/envelope/:Envelope'
    And the xml file is:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"...>
    </env:Envelope>

    The problem is that your DocumentBuilderFactory is not set to be namespace aware. If add a call to factory.setNamespaceAware(true) that should fix your problem.

  • Problem in reading a PDF output file using URL and HttpURLConnection class

    When i am reading a PDF file generated from a given URL, I am getting the response code as 200 but the content length is -1. Can anyone tell me what will be the problem and solution to this.

    form the api of the URLConnection
    the content length of the resource that this connection's URL references, or -1 if the content length is not known.
    Can anyone tell me what will be the problem and solution to this.The problem is that the server does not send the content length.
    Solution is to read the whole stream until -1 is returned.
    andi

  • Time and Pitch appears completely unusable at 96k (I/O Error-36)-any ideas?

    Hi there,
    Any help for the following gratefully received. Sorry about the excessive length of this post, but I've tried a whole bunch of things trying to sort out my problem and I'd rather list them all in the interests of clarity. (or should that be catharsis?)
    My simple question is: Is there anyone out there who is successfully using Time and Pitch compression / expansion at 96k? I simply can't get it to work with any degree of reliability on 2 new machines I've tried it on, and I've even managed to crash the demo machine in my nearest Apple Store trying it out.
    Some background: I recently ditched my TDM PT HD system in favour of a core audio Apogee Symphony based one. I use time compression / expansion of audio files extensively in my projects, and previously used the DAE version of Serato Pitch'n Time to do this. I've never rated the Logic Time and Pitch engine, so knowing that Serato and Izotope have developed Logic friendly algorithms was a big deal for me in finally making the hardware switch to a Mac Pro Twin 3.2Ghz Quad a few weeks ago.
    I've had quite a few problems / errors running Logic since then, resulting in me swapping the Twin 3.2Ghz Quad for a Twin 2.8Ghz Quad a couple of days ago. I reckon most of those errors are outside the scope of this question, but I'm happy to reel them out if people perversely want this post to be even longer. All those errors now seem to be sorted with the exception of the following:
    I've been trying to carry out a series of time compressions and expansions on a stereo 96k audio file to get it to play in time with my track, but the time stretching doesn't take place - I've been getting the 'I/O error Result Code= -36' message when I click the Process button. Not every time, but almost every time. It's more prone to do it with negative tempo change values for some reason, and if it does work, then an undo will almost certainly mess the audio up by not returning to the original state. It fails with both Logic's own algorithms and the dedicated Serato Pitch'n Time LE version. All other sample edit functions (say excite, denoise etc) appear to work correctly.
    Knowledge base here seems to imply that I'm getting a disk read / write error. I've tried resampling the audio. I've duplicated it and tried the copy. I've moved it to a different internal drive, having taken the first drive off line. I've moved it back again. I have four internal drives and I've tried audio running off each of them alone and in combination. I've given the file a new name with no gaps or punctuation. I've tried time stretching a completely different audio file chosen at random, usually to no avail but sometimes it works a few times, then fails. Mono files seem to be slightly more reliable, but not much. I've fixed disk permissions and all folder permissions more times than I care to mention. I've reinitialised the boot drive and reinstalled Logic. I've even installed OSX on a different drive, and installed Logic on that one, but that didn't work. I've tried it with my extra 8GB of (reliably sourced) third party RAM removed. I was getting this time-stretching error on the 3.2GHz machine as well, so you could even say I've tried it on two different machines (though it should be pointed out they had the same RAM and Hard Drives).
    At the Apple Store earlier today I tried to get a display machine (a 2 core MacPro) with a version of Logic on it (that I'd had nothing to do with) to replicate this error on the demo Logic song. When everything was 44.1 time stretching worked absolutely fine, many times, but once I converted one audio file from its default 44.1 kHz to 96 kHz and tried the time compression, up came the I/O error message. Now I can't believe it's a good idea to have different sample rates in the same song, so I converted all the audio files in the demo song to 96k in a different audio folder, changed the sample rate of the song so it would play back as you'd expect, saved and restarted, and then tried time stretching one of the files - it wouldn't do it, resulting in the I/O error again. Interestingly, after that even the 44.1 version of the song started showing the same error, even after another restart.
    It seems like I should work at 44.1 if I want to time stretch, but I like to work at 96k and I should be able to.
    This sounds like a proper bug to me and has been crippling my productivity, but I can't believe no one else has tried repetitively time stretching sections of an audio file at 96k - either have you been able to get it to work, or has anyone got any more suggestions I may not have tried out?
    Thanks in advance. (Or have you all gone to sleep by now? Self-editing was never my strong suit...!)

    Nevermind. I was low on disk space. Duh (though the error could have been a bit more descriptive).
    Move along. Nothing to see here, folks.

  • To use JMS and JNDI in JDev 9.0.3.4

    Do I need to add additional librararies in order to use JMS and JNDI along with EJB's in the enterprise application I'm creating?

    No the article is not applicable for 9.0.3 I've never tested the compatibility of the 9.0.3 + Struts integration - obviously it does not work.
    What does work is the ADF bindings used in 9.0.5 and above which can be safely used with newer versions of Struts.

  • Java.util.Timer and java.util.TimerTask running threads problem

    Hi,
    I have following scenario.
    1. My thread to send mail has to run at a fixed time interval thus I am using the following method from the Timer class.
    scheduleAtFixedRate(TimerTask object, start time, interval)
    2. My thread in the class checkDBSendEmail that extends TimerTask class reads database and sends mail based on the data received in the run() method.
    3. Whenever I send any mail, I log it into a database table that keeps the record of the emails sent.
    4. i have put it some logic to filter data form data base after that it will sends me unique data. Data should be email to different uses based on the list.
    Now the Problem:
    I am receiving duplicate mails on multiple times.
    Is there anything that I am missing in the following that would help me resolve this problem.
    my Servlet inti method is:

    sorry code is here..........
    public class SchduleTimeEmail extends HttpServlet implements SingleThreadModel{
    public void init( ServletConfig servletConfig ) throws ServletException{
    super.init(servletConfig);
    this.config = servletConfig;
    try{
    // specify in the format as in 12.13.52 or 3:30pm
    initialTime = format.parse( config.getInitParameter("initialTime"));
    delay = HOURS_24;
    RunLogger.addLogger("init first try:"); // log file
    catch( ParseException pe ){
    // Log.sendMessage( Log.MESSAGE_LEVEL_INFO , "[TimerServlet]", "startTime could not be parsed from web.xml file" );
    System.out.println("startTime could not be parsed from web.xml file."+pe);
    initialTime = new Date();
    delay = HOURS_24;
    // Timer Must start combination of 15,30,45,00 min for check schdule
    Date dalayTimeMinSec = new Date();
    int currentMin = dalayTimeMinSec.getMinutes();
    int totalDelayTime = 0;
    if(currentMin%15!=0 || currentMin%15 != 15){
    try {
    int delayMin = currentMin % 15;
    totalDelayTime = (15-delayMin) * 1000 * 60;
    dalayTimeMinSec.setSeconds(0);
    Thread.sleep(totalDelayTime);
    RunLogger.addLogger("Thread go for sleep:");
    } catch (InterruptedException ex) {
    RunLogger.addLogger(ex.toString());
    //Start Timer from this time
    timer = new Timer();
    Calendar time = Calendar.getInstance();
    Calendar timeOfDay = Calendar.getInstance();
    try{
    timeOfDay.setTime(initialTime);
    time.set((Calendar.HOUR_OF_DAY), timeOfDay.get(Calendar.HOUR_OF_DAY));
    time.set(Calendar.MINUTE, timeOfDay.get(Calendar.MINUTE));
    time.set(Calendar.SECOND, timeOfDay.get(Calendar.SECOND));
    Calendar startTimeOfTimer = Calendar.getInstance();
    startTimeOfTimer.add( Calendar.MINUTE, 0 );
    // make sure the first timer doesn't fire before the server starts
    if( time.before(startTimeOfTimer) )
    time = startTimeOfTimer;
    System.out.println("TimerServlet: Timer has been set for " + time.getTime() + " '(" + delay + ")'"); // for checking
    checkDBSendEmail msasTask = new checkDBSendEmail();
    timer.scheduleAtFixedRate( msasTask, time.getTime(), delay );
    catch( Exception e ){
    RunLogger.addLogger(e.toString());
    public void destroy(){
    timer.cancel();
    super.destroy();
    and another class is:..
    public class checkDBSendEmail extends TimerTask{
    public void run()
    // System.out.println("Function run : "+ functionExcuteCount++);
    try{
    // DB Logic as well as send e-mail function call
    catch( Exception ex ){
    RunLogger.addLogger(ex.toString());
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    public String getServletInfo() {
    return "Short description";
    // </editor-fold>
    I also checked the email server settings, and I am sure that the email server is not duplicating the emails.
    this code working correctly on my local machine But in live server it duplicating email and still I am receiving duplicate mails.
    Any help is appreciated.
    Thanks,
    Sharda

  • When to use interface and when Abstract Class?

    In a recent interview I was asked "When to use interface and when Abstract Class?" Explain with an example.
    Also in what situations a class should be made final(real time example)

    Interface is a pure contract with no implementation. Typically used to define a communication contract between two different sub-systems. Example EJB home interface. This also allows the design to change as long as the contract is met.
    Abstract class is when there exists a lot of common functionality already known and can be coded. However, a few unknowns exists (typically about data) for which abstract methods need to be defined and implemented by the sub class.
    Example: Consider a workflow engine. A great example for abstract class. The workflow process has lot of common code that is independent of the workflow type (vendor flow, contract flow, payment flow etc). However, certain decisions on the route to take will depend on value of data being submitted. So the base class will define a abstract Data getData() method and proceed assuming data will come. The implementing subclass will provide the actual logic for getting the data.
    Also see the "Template" design pattern.
    Note: To some extent the common code design drives the behavior of the abstract methods. So if the design changes then so "might" the behavior expected from the abstract methods.

  • When I use Firefox and Hotmail at startup, Firefox freezes for about 1 minute, and then I can continue. First I though it was my computer but 2 other girls in my class have the same problem with Hotmail and Firefox. What can I do to change this?

    When I start Firefox, about 15 seconds after I start it, my Firefox freezes for about 1 minute. I found out that it is my Hotmail that makes Firefox freeze.
    First I thought it was my computer, but I have 2 other girls in my class that use Hotmail and Firefox and their computer also freezes for 1 full minute.
    This is very annoying, what can I do to change this?
    xxx ellen
    p.s. I am from the Netherlands, maybe that has something to do with it?

    Try deleting cookies and cache:
    1. Tools| Clear recent history
    2. Time range to clear: Everything
    3. If it isn't already selected, select '''Cookies''' and '''Cache'''
    4. '''Clear now'''
    '''Check cookie exceptions'''
    1. Tools | Options | Privacy Panel
    2. Set '''Firefox will: Use custom settings for history.''' '''Insure Accept cookies for sites and accept third-party cookies''' is selected
    3. Click '''Exceptions'''. If the misbehaving site is in that list, select it and click '''Remove site'''
    '''Safe Mode'''
    Add-ons can cause problems with not being able to log into certain websites. To see if this is the case with your issue, run [[Safe mode]]. When you get to the safe mode window, select Continue in Safe Mode. If this resolves your problem, see [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    Also see [[Updating Firefox]] and [[Cannot log in to websites]]

Maybe you are looking for

  • When trying to play a song from a play list on my phone it automatically skips to another song

    This is happening on my ipod and iphone; I'll select a song to start playing from a playlist and it automatically skips ahead 1-3 songs and starts playing, and whenever I try to play that song it does it again. Some songs we put into itunes from disk

  • Very slow first Mobile Service call after one minute incativity

    My mobile service api (basic tire) response about 30 sec delay for the first call. The subsequent calls are fine but the first call even sometimes times out. Which is totally unacceptable. The worse is that after one minutes inactivity it stars again

  • PA GL IMPORT시 GROUP ID MISSING

    제품: FIN_GL 작성날짜 : 2006-05-30 PA GL IMPORT시 GROUP ID MISSING ============================== PURPOSE 특정 Group ID에 IMport가 안될경우 Problem Description "No records exist for this Source with a Group ID"에러 메시지로 GL Import가 안됨 Workaround gl_interface_control i

  • Is there any way I can get back an older version of Pages, the Version 5.0 is useless to me

    I feel really dumb as I do not have a backup of the older versions and I thought, that Apple might only add some bug fixes or style changes to the new versions, but the way it functions right now makes it useless to me... No I would like to know If I

  • Ipad 2 will not sync edited photos from iphoto

    I've changed some of my photos to black and white or sepia in iphoto.  When I sync them to my ipad 2, they remain in color.  Any ideas?  It's only happened to pictures edited within the past month or so.  Wondering if it coincides with a recent iphot