Servlets: Will the value of the counter be kept?

Good morning fellow forum users.
I'm using a static counter.class to keep track of the number of times an input is made.
import java.util.*;
import java.awt.*;
public class counter {
static private int count = 0;
public counter() {
} // constructor
static public void increment() {
     count++;
}// end of increment()
static public int getCount() {
     return count;
} // end of getCount()
} // end of counter class
In the program, whenever an input is being made by the user, I'd call
counter.increment();
the same servlet is called by different JSP pages
(eg. init.jsp -> select.jsp -> select.jsp -> select.jsp etc)
I check for the counter value using an
if (counter.getCount() == 3) { do something };
but this "do something" is never executed.
Query 1: Is my Static counter's value still valid when different JSP pages call it?
Query 2: Is there anyway i can system.out.println(counter.getValue()) to check my counter value, for nothing is shown when i used that in my servlet.
Thank you for your kind attention! :)

(1)Synchronize the methods.
(2)Your counter class does not need constructor.
I check for the counter value using an
if (counter.getCount() == 3) { do something };
but this "do something" is never executed.Because it was not 3.
Query 1: Is my Static counter's value still valid when different JSP
pages call it?Use synchronization. It should be valid if your definition of 'valid' is proper.
Query 2: Is there anyway i can
system.out.println(counter.getValue()) to check my counter value,
for nothing is shown when i used that in my servlet.No such method: counter.getValue()
Message was edited by:
hiwa

Similar Messages

  • If Mavericks is updated from snow leopard, will the drivers be kept intact for my printer and other aps?

    If I upgrade from Snow Leopard to Mavericks, will my drivers be kept, and will my settings for Safari and Mail be kept?

    Yes. Upgrading doesn't muck with your or 3rd-party stuff unless the latter is incompatible. Then, the installer will those things into a root-level folder entitled Incompatible Software. As for your printer, ensure that you install the latest printer update before upgrading. Also, note that all PPC apps will no longer work.

  • I have a ASCII input feeding a value in. Each time this value falls between two numbers I want to increase the count by 1. How can I do this?

    I have been trying to work this out an I am sure is is not too difficult to do, but I cant seem to get anywhere with it. If anyone could help that would be great.
    Thanks
    RossH

    I am not currently at a PC with LabVIEW on, so Ic ant send you an example of how to do this. Instead you'll have to understand my description....
    I'll assume that you want to constantly monitor the input value...
    Use a while loop with a shift register to store the count value. You can initialise the count value to zero (or whatever you like) by wiring a numeric constant to it - to the left of the shift register - outside the loop. Place a case structure inside the loop and wire the shift register left to right through the false case. In the true case place the increment function and connect it between the input and output nodes you now have on the case structure. On each iteration of the loop the count value will either remain the same or be incremented b
    y one depending on whats wired to the boolean input on the case structure. Now you need to detect whether your ascii value is in range. You can use the 'In range and coerce' function for this (found in the comparison function pallette). Wire the range values and the input value to it and take the boolean output to the input of the case structure. The ascii value must be acquired within the loop, so that you are checking the updated value on each iteration (or if it comes via an array you could wire the array directly to the outside of the loop and enable indexing - in this case it would be best to use a for loop). You can place an indicator on the 'count' wire to monitor its value if you wish. Remember to also place some conditional statement to stop the loop when required and also a wait function should exist inside the loop. When the loop stops, the count value will be available at the output of the shift register.
    Hope this helps and is clear enough for you to implement?!

  • To get the count of records and able to access the column value in a single

    Hi
    Is there any way to get the number of records in the query and access the column values
    e.g
    select count(*)
    from
    (SELECT department, COUNT(*) as "Number of employees"
    FROM employees
    WHERE salary > 25000
    GROUP BY department ) a
    This wil only get the Count, if i want to access each row from the inline view how can i do that.

    Your question is not clear.
    Are you looking for total record count as well as count by department ?
    Something like this?
    SQL>
    SQL> with temp as
      2  (
      3  select 1 dept ,10000 sal from dual union
      4  select 1 dept ,25100 sal from dual union
      5  select 1 dept ,30000 sal from dual union
      6  select 1 dept ,40000 sal from dual union
      7  select 2 dept ,10000 sal from dual union
      8  select 2 dept ,25100 sal from dual union
      9  select 2 dept ,30000 sal from dual union
    10  select 2 dept ,40000 sal from dual )
    11  select count(*) over( partition by 1 ) total_count,dept,
    12  count(*) over(partition by dept) dept_cnt  from temp
    13  where sal>25000;
    TOTAL_COUNT       DEPT   DEPT_CNT
              6          1          3
              6          1          3
              6          1          3
              6          2          3
              6          2          3
              6          2          3
    6 rows selected
    SQL>

  • What is the "Count" property for Servlet in Console?

    Wondering what the "Count" property for Servlet means in the Console. Is it instances
    or current uses? In other words, if the number is >1 does this mean that the Servlet
    implements the single-threaded model?
    Thanks,
    -Daniel

    btw one of the nice things about java is if you can't find the answer
    in the API or you are not sure what the API is saying you can always
    look at the source for the class your are looking at. the source files
    are in a file called src.zip or src.jar depending on the version.
    anyway just to make sure i understood i looked at the properties method
    in question.
    public String getProperty(String key) {
         Object oval = super.get(key);
         String sval = (oval instanceof String) ? (String)oval : null;
         return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
        public String getProperty(String key, String defaultValue) {
         String val = getProperty(key);
         return (val == null) ? defaultValue : val;

  • How do I count and display events every few seconds and then convert the counted values into events per minute? (for a heart rate monitor)

    Hi everyone,
    I'm building a heart rate monitor as a final year project with my lab partner using the NI USB-6009 and Labview 2009. We have managed to obtain a signal using a photo transciever, smooth it out and count the events, however the count is incremental.
    We wish to count the number of pulses we obtain for a few seconds (5-10 for example) and then use this value to obtain a pulse rate in beats per minute (e.g. 10 pulses in the first 10 seconds would give an estimated BPM of 60 etc etc).
    Does anybody have ides on how we could implement this? We have tried timed loops, elapsed time VI's and other things but nothing gives us what we need.
    Thanks in advance for any help that is offered.
    Jeshua Graham.

    We are very new to Labview. We are taking a raw signal from our DAQ and then using VIs to filter and then trigger counts on rising edges. I have attached our vi file to this post for you to look at (I hope that is what you mean by code).
    Attachments:
    TCRT-1010DAQ_jeshua1.vi ‏367 KB

  • If you change the image mode of this image from 8-bit RGB image to Grayscale mode while in PSCS – what will the new Pixel Count be?

    If you change the image mode of this image from 8-bit RGB image to Grayscale
    mode while in PSCS – what will the new Pixel Count be?

    If you mean by Pixel count the number of pixels, this will not change. The image will have the same size thus the same number of pixels.

  • Getting Value Based on Descending value of the count

    Hi,
    I have values in the list as below
    Title,Count
    title1,3
    title2,5
    title3,4
    Now i need to fetch the title column value based on descending order of the count column value.
    But writing spquery as below but not getting the exact value
    "<OrderBy><FieldRef Name='Count' Ascending='FALSE' /></OrderBy>";
    Please let me know if i am making any mistake here.
    Regards,
    Sudheer
    Thanks & Regards, Sudheer

    Hi,
    In addition to Hemendra, there is OOB option to order items in descending order per one column value.
    You could create a view for this list, and configure in Sort section.
    Regards,
    Rebecca Tu
    TechNet Community Support

  • Calculating the Count value

    Hi friends,
    I have personnel planning cube,i need to calculate the no.of Personal Id's for each cost center..and retreive the Count value and save it to a keyfigure with type Number.
    I know that we can do this in FOX,Can anyone please provide me with the sample code for the above requirement.
    Thanks In Advance.
    Regards,
    Ravi.
    Edited by: ravi kanth on Sep 15, 2009 12:34 PM

    Hi Ravi,
    Counter type I.
    FOREEACH PERSONAL ID.
    COUNTER = COUNTER +1.
    {KF, Personal id} = {KF, Personalid}.
    ENDFOR.
    (Count,personalid} = counter.
    Hope this gives you an Idea but let me know you need more information.
    Regards,
    Raj

  • I have an iphone 4S and it is within the warranty period. However my power button is jammed. Will i get an over the counter replacement in any store in the USA?

    I am currently situated in India and they have a messed up replacement policy but, if i send my phone with the bill and everything will i get an over the counter replacement? The phone was bought in August 2012 and the power button jammed in November 2012. Also, does Apple only replace the phone or the earphones and everything that comes with it?

    You will have to physically take the iPhone to an Apple store in the US,
    if that is where it was purchased. If you are not going to be in the US, send
    it to a friend or relative there to take into Apple for you, and then that person
    can ship it back to you - shipping costs and insurance are your responsibility.
    Apple does not accept international shipments for replacement nor will Apple
    ship a replacement out of the country where replacement is made. Only your
    iPhone - if determined to be defective - will be replaced, and your iPhone is all
    you need to take to Apple.
    iPhone warranty is valid only in country of original purchase - it has always been
    this way for iPhones. The replacement policy is not messed up - it is working as
    designed. Apple India would not have the correct handset to replace the one you
    purchased in the US.

  • If I convert the songs on my iPhone to 128 kbps, will the play counts still sync with what's on my computer?

    If I convert the songs on my iPhone to 128 kbps, will the play counts still sync with what's on my computer? I have a lot of songs on my iPhone which are at the 256 kbps bitrate, and if I take them down to 128 kbps on my iPhone, I'll be able to fit a lot more music on my iPhone. But...I really would like to keep the play counts between my iPhone and my Mac in sync. Will that still happen if I switch, or will there be an issue?

    Anybody?

  • HT4914 I have 25 GB of songs on my Ipod. I want to buy an IPAD. If I use ICloud to sync my music, will the IPAD use 25 gigs of space? I am trying to decide which I pad to get and 32 Gigs would be plenty, if the 25 gigs already on my Ipod do not count.

    I own an Ipod with 27 GB of music. I am considering an Ipad. If I use ICloud to sync my devices, will the new Ipad use 27 GB? The answer to this question will affect which GB size Ipad that I buy. Thanks!

    If you put the music on the ipad, then it will use the space.

  • When will the Blackberry os systems be avaliable without values being lost

    Windows 8 phone os helping with the free trial of Azure for servers but what about developer mode not being lost
    Is AMD responsible , will the steam network prove to be most valuable for floppy search solutions or are all media programs for a short trial not reaching any events.
    Apparently all data lost

    Mr. Jones,
    You are a real lifesaver!!!
    It worked on the Mac.  Will have to do some searches to find the same on the PC since the same is happening.
    Do you happen to know why Adobe is saying they are not compatible with Office 2011 now?  I found a link on the Adobe webite along those lines yesterday, but was not able to find it this morning to insert into this post.
    Our CEO had a real meltdown at about 2am the other morning when trying to pdf something for a meeting the next day.  Was not very pretty.
    THANK YOU!!!

  • SQL JSTL  displat y the count ..  cant figure out how please help......

    Hi all,
    I facing a problem in displaying the count total.. My situation is that I run below query ..
    <sql:query var="jobs" dataSource="jdbc/test">
              SELECT COUNT(*) FROM applications where employerid = '12345610' GROUP BY job_id
              </sql:query>
              <c:forEach var="row" items="${jobs.rows}">
              <li> Count <span id="count"> [<c:out value="${row.??? )}]</span></li>
              </c:forEach>
    {code}
    when I run the same sql in sql prompt it gives me 10 groups with relevant counts.
    but I cant figure out how to do the same using JSTL sql.  in simple terms I want to display the count of each logical group ?  I have tried all I can wit my little knowledge on the subject..
    I will appreciate if someone could help me out please..
    Million Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I found the answer my self... It took me just a 4 sleep to find the answer ,,, a break and a coup of coffee did the job
    I chanced the code as below
    SELECT COUNT(*) as cnt FROM applications where employerid = '12345610' GROUP BY job_id
              </sql:query>
              <c:forEach var="row" items="${jobs.rows}">
              <li><a href="/test/servlet/Controller?param=Security">Security </a><span id="count">[<c:out value="${row.cnt }"/>]</span></li>

  • Can DAQmxRegisterEveryNSamplesEvent function be used for the Counter Input Channels

    Hi, All,
    I have an application to count the digitial pulse number. I want to know the time of the coming pulses which start from 1 and increased 4 later, like 1, 5, 9, 13..... The time interval between each pulse is not a fixed value. So I tried to use  DAQmxRegisterEveryNSamplesEvent and DAQmxCreateCICountEdgesChan functions. But afterI called the DAQmxStartTask function, it always failed.  The board I used is the NI-PCIe-6320. Here is part of my code.
    DAQmxErrChk (DAQmxCreateTask("",&m_taskhandle));
    DAQmxErrChk (DAQmxCreateCICountEdgesChan(m_taskhandle,"Dev1/ctr0","",DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
    DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(m_taskhandle, DAQmx_Val_Acquired_Into_Buffer, 4, 0, EveryNSamplesCallback, this) );
    DAQmxErrChk (DAQmxStartTask(m_taskhandle));
    I don't know the reason. Can Anyone give me some help. Thanks.
    Yang
    Solved!
    Go to Solution.

    Hi, John,
    What's I what to do is that I have an external digital signal, when the signal goes from low to high, I need do some operations. So I just want to know the time when the digital signal goes from low to high.  The frequency of the digital signal is from 0 - 20000Hz. My first plan is to use a counter to count the pulse rising edges. When the number of edge increases one, I do the designed operations. In this method, I can't guarantee I can catch each pulse rising point. Because sometimes the counter will increase more than one in the on-demand mode. For example, the previous content of the counter is xxxx4, but the next reading the content may become xxxx6.
    After I learned some ANSI C  codes, I found that the ChangeDetectionEvent can help me found time when the signal goes from low to high. So I wrote the following code: (I set the digital signal to P0.0)
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev1/port0/line0","",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle,"Dev1/port0/line0","",DAQmx_Val_ContSamps, 1));
    DAQmxErrChk (DAQmxRegisterSignalEvent (taskHandle, DAQmx_Val_ChangeDetectionEvent, 0, Callback , dialog));
    DAQmxErrChk (DAQmxStartTask(taskHandle));
    int32 CVICALLBACK Callback (TaskHandle taskHandle, int32 signalID, void *callbackData){
    CNIPCIE6320Dlg* dialog = static_cast<CNIPCIE6320Dlg*>(callbackData);
    dialog->m_event_num++;  // Here is to calculate how many events has been triggered
    return 0;
    Yesterday I used this method to get the pulse rising time. I found the m_event_num is close to the ground truth (In the simulation, I know how may rising pulse I generated).  In one two hours test, the offset is almost 400 pulses. But today I did the same tests again. I found the m_event_num got a big difference from the ground truth. The voltage of the whole system today maybe smaller than yesterday, because today the power is from an invertor while yesterday the power is from the electricity supply. So will the lower voltage supply will causing some event missing. Or if PC system became busy will ignore some callings of the event callback function? That's two possible reason will affact the final result. I am not sure. Do you have any experience about this problem.  Or do you have some better suggestion to get the pulse rising time. Thanks again.
    Regards,
    Yang 

Maybe you are looking for

  • Customizing af:document uncommittedDataWarning

    JDeveloper Version 11.1.1.2.0 I'm using the <af:document uncommittedDataWarning="on" property as discussed on http://www.oracle.com/technology/products/adf/patterns/11/UnsavedDataWarning.html Is it possible to overwrite the popup message with a new m

  • Clearing NaN error from form fields.

    Hey all, Working with this script I have and I thought my condition should clear the NaN erro but it does not.  Does anyone have a clear for the NaN error that might work better.  Basicully,  all the script does is the person using it puts military t

  • New classic with third part USB pci card

    Hi, Just got a new 120gb classic for my son. But it does not seem to work with his computer. He has an old g4 tower, with third part usb 2 card. That worked fine with his 30gb video, but the new 120gb classic is not even recognised by the system. It

  • Adobe Falsh Player Notifications

    Need to turn off Adobe Flash Player notfications:  Have done the Global Notifications Settings thing

  • Ayttm PKGBUILD update/Help needed

    The PKGBUILD in the aur is  badly outdated..V0.6.2 of ayttm is out . .and the PKGBUILD in the aur was to build v0.5 ... I have made a PKGBUILD of ayttm git over here http://aur.pastebin.com/9sMXVMz4 Apart from that ,  building of ayttm fails.. Both w