Required_checkpoint_scn and first_scn

Hi All,
Could anyone please help me in understanding required_checkpoint_scn and first_scn usage in STREAMS.
Seems like both are used for same functionality according to manuals.
From link: http://download.oracle.com/docs/cd/B14117_01/server.101/b10727/capture.htm#1011367
When the capture process is restarted, it scans the redo log from the required checkpoint SCN forward. Therefore, the redo log file that includes the required checkpoint SCN, and all subsequent redo log files, must be available to the capture process.
The first SCN for a capture process can be reset to a higher value, but it cannot be reset to a lower value. Therefore, a capture process will never need the redo log files that contain information prior to its first SCN. Query the DBA_LOGMNR_PURGED_LOG data dictionary view to determine which archived redo log files will never be needed by any capture process.Please help me in understanding dependency or difference of these two SCN values.
-Yasser

See this link.
REQUIRED_CHECKPOINT_SCN

Similar Messages

  • Persisting Messages in Buffered Queues

    Hello Everyone,
    As per the oracle documentation http://docs.oracle.com/cd/B28359_01/server.111/b28321/strms_prop.htm#i1006905
    LCRs that were captured by a capture process are always stored in a buffered queue, but LCRs that were captured by a synchronous capture are always stored in a persistent queue.
    This means that if we use Capture process and server goes down( or is restarted), we will loose those messages in buffered queues as messages are stored in memory.
    1) Is there a way to force capture process to persist the message into persistent queue?
    2) Is there a way to recover the messages from buffered queue when we restart the server?
    Please let me know if you have some ideas / some insights for above two cases.
    Thanks
    Nithin
    Edited by: 906226 on Jan 5, 2012 11:20 AM

    Hello,
    This is really a Streams question.
    When the database goes down the buffered messages are lost. However when the instance restarts the Capture re-mines the redo logs from the required_checkpoint_scn and then re-enqueues the LCRs. The apply also keeps track of where it was at via the apply progress So nothing is lost in the Streams scenario when an instance goes down. This is discussed in the documentation.
    In the AQ world if you are using a buffered queue then the messages would be lost and the application would have to handle that situation.
    Thanks
    Peter

  • The (stopped) Capture process & RMAN

    Hi,
    We have a working 1-table bi-directional replication with Oracle 10.2.0.4 on SPARC/Solaris.
    Every night, RMAN backs up the database and collects/removes the archive logs (delete all inputs).
    My understanding from (Oracle Streams Concept & Administration) is that RMAN will not remove an archived log needed by a capture process (I think for the logminer session).
    Fine.
    But now, If I stop the Capture process for a long time (more than a day), whatever the reason.
    It's not clear what is the behaviour...
    I'm afraid that:
    - RMAN will collect the archived logs (since there is no more logminer session because of the stopped capture process)
    - When I'll restart the capture process, it will try to start from the last known SCN and the (new) logminer session will not find the redo logs.
    If that's correct, is it possible to restart the Capture process with an updated SCN so that I do not run into this problem ?
    How to find this SCN ?
    (In the case of a long interruption, we have a specific script which synchronize the table. It would be run first before restarting the capture process)
    Thanks for your answers.
    JD

    RMAN backup in 10g is streams aware. It will not delete any logs that contain the required_checkpoint_scn and above. This is true only if the capture process is running in the same database(local capture) as the RMAN backup is running.
    If you are using downstream capture, then RMAN is not aware of what logs that streams needs and may delete those logs. One additional reason why logs may be deleted is due to space pressure in flash recovery area.
    Please take a look at the following documentation:
    Oracle® Streams Concepts and Administration
    10g Release 2 (10.2)
    Part Number B14229-04
    CHAPTER 2 - Streams Capture Process
    Section - RMAN and Archived Redo Log Files Required by a Capture Process

  • Oracle stream - first_scn and start_scn

    Hi,
    My first_scn is 7669917207423 and start_scn is 7669991182403 in DBA_CAPTURE view.
    Once I will start the capture from which SCN it will start to capture from archive log?
    Regards,

    I am using oracle 10.2.0.4 version oracle streams. It's Oracle downstream setup. The capture as well as apply is running on target database.
    Regards,
    Below is the setup doc.
    1.1 Create the Streams Queue
    conn STRMADMIN
    BEGIN
    DBMS_STREAMS_ADM.SET_UP_QUEUE(
    queue_table => 'NIG_Q_TABLE',
    queue_name => 'NIG_Q',
    queue_user => 'STRMADMIN');     
    END;
    1.2 Create apply process for the Schema
    BEGIN
    DBMS_APPLY_ADM.CREATE_APPLY(
    queue_name => 'NIG_Q',
    apply_name => 'NIG_APPLY',
    apply_captured => TRUE
    END;
    1.3 Setting up parameters for Apply
    exec dbms_apply_adm.set_parameter('NIG_APPLY' ,'disable_on_error','n');
    exec dbms_apply_adm.set_parameter('NIG_APPLY' ,'parallelism','6');
    exec dbms_apply_adm.set_parameter('NIG_APPLY' ,'_dynamic_stmts','Y');
    exec dbms_apply_adm.set_parameter('NIG_APPLY' ,'_hash_table_size','1000000');
    exec dbms_apply_adm.set_parameter('NIG_APPLY' ,'_TXN_BUFFER_SIZE',10);
    /********** STEP 2.- Downstream capture process *****************/
    2.1 Create the downstream capture process
    BEGIN
    DBMS_CAPTURE_ADM.CREATE_CAPTURE (
    queue_name => 'NIG_Q',
    capture_name => 'NIG_CAPTURE',
    rule_set_name => null,
    start_scn => null,
    source_database => 'PNID.LOUDCLOUD.COM',
    use_database_link => true,
    first_scn => null,
    logfile_assignment => 'IMPLICIT');
    END;
    2.2 Setting up parameters for Capture
    exec DBMS_CAPTURE_ADM.ALTER_CAPTURE (capture_name=>'NIG_CAPTURE',checkpoint_retention_time=> 2);
    exec DBMS_CAPTURE_ADM.SET_PARAMETER ('NIG_CAPTURE','_SGA_SIZE','250');
    2.3 Add the table level rule for capture
    BEGIN
    DBMS_STREAMS_ADM.ADD_TABLE_RULES(
    table_name => 'NIG.BUILD_VIEWS',
    streams_type => 'CAPTURE',
    streams_name => 'NIG_CAPTURE',
    queue_name => 'STRMADMIN.NIG_Q',
    include_dml => true,
    include_ddl => true,
    source_database => 'PNID.LOUDCLOUD.COM'
    END;
    /**** Step 3 : Initializing SCN on Downstream database—start from here *************/
    import
    =================
    impdp system DIRECTORY=DBA_WORK_DIRECTORY DUMPFILE=nig_part1_srm_expdp_%U.dmp table_exists_action=replace exclude=grant,statistics,ref_constraint logfile=NIG1.log status=300
    /********** STEP 4.- Start the Apply process ********************/
    sqlplus STRMADMIN
    exec DBMS_APPLY_ADM.START_APPLY(apply_name => 'NIG_APPLY');

  • Capture and Logminer Dictionary

    Hi All,
    Please clarify my understanding and doubts in STREAMS.
    1. FIRST_SCN in dba_capture shows the mark from where Log Dictionary has been stored in the log file, but FIRST_SCN keeps advancing forward due to CHEKPOINT_FREQUENCY and CHECKPOINT_RETENTION_TIME , these log files which are present below the FIRST_SCN are marked as purgeable in DBA_LOGMNR_PURGED_LOG view.
    My doubt is how object name and column name are resolved using Logminer Dictionary when FIRST_SCN keeps on advancing and Logminer Dictionary containing log file is deleted by querying DBA_LOGMNR_PURGED_LOG.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    set linesize 172
    set pagesize 66
    column  Status format a10     heading "Status"
    column  first_change# format 999999999999
    column  next_change#  format 999999999999
    column  ft    format a21      heading "First time" justify c
    column  nt    format a21      heading "Next time" justify c
    column  sta   format a7       heading "Standby|Dest" justify c
    column  del   format a7       heading "Deleted|By Rman" justify c
    column  dic   format a3       heading "Dic|Beg"
    prompt
    select thread#, SEQUENCE#,  FIRST_TIME, NEXT_TIME,
           applied, '    '|| status status, sta, del, registrar,  DICTIONARY_BEGIN Dic
        from ( SELECT thread#, SEQUENCE# ,  FIRST_TIME, NEXT_TIME,
                      applied, status, '  '||standby_dest  sta,'  '||deleted del, registrar , DICTIONARY_BEGIN
                      FROM V$ARCHIVED_LOG ORDER BY first_time desc)
       where rownum <= 40
                                                                                     Standby Deleted                       Dic
       THREAD#  SEQUENCE# FIRST_TIME         NEXT_TIME          APPLIED   Status      Dest   By Rman REGISTRAR             Beg
             2       3139 18-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3139 18-FEB-10          18-FEB-10          NO            A        YES     NO    ARCH                  NO
             1       3509 18-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3509 18-FEB-10          18-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3138 18-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3138 18-FEB-10          18-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3508 18-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3508 18-FEB-10          18-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3507 17-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3507 17-FEB-10          18-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3506 17-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3506 17-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3137 17-FEB-10          18-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3137 17-FEB-10          18-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3136 17-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3136 17-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3505 17-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3505 17-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3135 17-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3135 17-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3504 16-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3504 16-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3503 16-FEB-10          16-FEB-10          NO            A        NO      NO    ARCH                  NO
             1       3503 16-FEB-10          16-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3134 16-FEB-10          17-FEB-10          NO            A        NO      NO    ARCH                  NO
             2       3134 16-FEB-10          17-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3133 16-FEB-10          16-FEB-10          NO            D        NO      YES   ARCH                  NO
             2       3133 16-FEB-10          16-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3502 16-FEB-10          16-FEB-10          NO            D        NO      YES   ARCH                  NO
             1       3502 16-FEB-10          16-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3501 15-FEB-10          16-FEB-10          NO            D        NO      YES   FGRD                  NO
             1       3501 15-FEB-10          16-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3132 15-FEB-10          16-FEB-10          NO            D        NO      YES   ARCH                  NO
             2       3132 15-FEB-10          16-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3131 15-FEB-10          15-FEB-10          NO            D        NO      YES   ARCH                  NO
             2       3131 15-FEB-10          15-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3500 15-FEB-10          15-FEB-10          NO            D        NO      YES   ARCH                  NO
             1       3500 15-FEB-10          15-FEB-10          YES           A        YES     NO    ARCH                  NO
             1       3500 15-FEB-10          15-FEB-10          YES           A        YES     NO    ARCH                  NO
             2       3130 15-FEB-10          15-FEB-10          NO            D        NO      YES   ARCH                  NO
    40 rows selected.None of the log file is having Logminer Dictionary, what will happen if restart Capture process....From which SCN(START_SCN,CAPTURED_SCN,APPLIED_SCN,FIRST_SCN,REQUIRED_CHECKPOINT_SCN,MAX_CHECKPOINT_SCN) Capture starts mining or capturing changes.
    SQL> select START_SCN,CAPTURED_SCN,APPLIED_SCN,FIRST_SCN,REQUIRED_CHECKPOINT_SCN,MAX_CHECKPOINT_SCN from dba_capture;
    START_SCN CAPTURED_SCN APPLIED_SCN  FIRST_SCN REQUIRED_CHECKPOINT_SCN MAX_CHECKPOINT_SCN
    3.6116E+10   3.7127E+10  3.7127E+10 3.6116E+10              3.7127E+10         3.7127E+102. At last how to find whether bi-directional streams are in sync and how to find the gap in terms of LCR or Time metrics??
    -Yasser

    Thanks a lot for replying.
    Please find details below.
    SQL> select bytes/1024/1024 MB from dba_segments where segment_name='LOGMNR_RESTART_CKPT$' and owner='SYSTEM';
            MB
            15How come without Logminer Dictionary information Capture process is able to resolve object and column names. Where does the dictionary infromation is stored??
    From which SCN Capture process starts mining, if i restart Capture process??
    What is point-in-time recovery using streams, and why we need to set first_scn here??
    When START_SCN , CAPTURED_SCN , APPLIED_SCN , FIRST_SCN , REQUIRED_CHECKPOINT_SCN are used in Streams.....these SCN values creates too much confusion....
    -Yasser

  • REQUIRED_CHECKPOINT_SCN

    I have set up a 1-to-1 one-way streams replication in Oracle 10.2. (table subset level capture).
    Source DB on : SUSE Linux Enterprise Server 10 SP2 (ia64)
    Destination DB : Windows XP ver 2002 SP1
    The capture process has a problem that is random. The REQUIRED_CHECKPOINT_SCN is 0 after I configure and start the capture process. Please see below:
    SQL> select capture_name, START_SCN, first_scn, CAPTURED_SCN, APPLIED_SCN , REQU
    OINT_SCN, status, error_message from dba_capture;
    CAPTURE_NAME                    START_SCN  FIRST_SCN CAPTURED_SCN APPLIED_SCN
    REQUIRED_CHECKPOINT_SCN STATUS
    ERROR_MESSAGE
    CAP_SRC1                        51613753   51613753     51631481    51631481
                          0 ENABLED
    +
    1 row selected.Can you please help? I understand that REQUIRED_CHECKPOINT_SCN should have a valid value.

    Hello,
    If the required checkpoint scn is not populated, then the first thing you need to check would be whether the logminer checkpoints are happening. Check the following:
    select valid,count(*) from system.logmnr_restart_ckpt$ group by valid;
    Check if you find any checkpoints reported for valid = 1.
    Force few checkpoints manually:
    execute dbms_capture_adm.set_parameter('capture_name','_checkpoint_force','y');
    execute dbms_capture_adm.set_parameter('capture_name','_checkpoint_force','y');
    execute dbms_capture_adm.set_parameter('capture_name','_checkpoint_force','y');
    Check again to see if the count increases for valid = 1.
    select valid,count(*) from system.logmnr_restart_ckpt$ group by valid;
    If this does not happen then consider raising an SR with Oracle Support Services. There are few known bugs on required checkpoint scn not moving and becoming 0 etc.
    Thanks,
    Rijesh

  • Capture setup using first_scn parameter

    Hello
    I am trying to setup capture and having issues when doing a 'point in time' streams capture setup.
    I started my target from a hot backup of the source and then I setup the capture process
    to start from the SCN when the back was taken.
    When I pass the first_scn parameter and start the capture process, I get "WAITING FOR DICTIONARY REDO"
    message. Basically, I get this message anytime I create the capture with a value for first_scn parameter( any past SCN number
    that is still in the archive files)
    I am on 10.2.0.2 and applied 5602452 patch.
    Any advise would be greatly appreciated.
    thanks.

    Hi
    After the dictionary build, prepare the table(s) or schema(s) for instantiation and set the supplemental logging:
    example
    BEGIN
    DBMS_CAPTURE_ADM.PREPARE_SCHEMA_INSTANTIATION(
    schema_name =>'HR',
    supplemental_logging => 'keys');
    END;
    In the supplemental logging you can put whatever you need but at least you need the keys. Now, if you are filtering tables, just set the supplemental logging for the tables you are interested in.
    After step 4 :
    In the target database, you have to set the instantiation scn for the table(s) or schema(2) using the same scn as the start_scn you specified in your capture:
    For example if you want to do it for a whole schema use the following procedure:
    DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN(
    source_schema_name IN VARCHAR2,
    source_database_name IN VARCHAR2,
    instantiation_scn IN NUMBER, -- Here you put your start_scn
    apply_database_link IN VARCHAR2 DEFAULT NULL,
    recursive IN BOOLEAN DEFAULT FALSE);
    Let me know if you need further assistance,
    Aldo

  • Capture : required_checkpoint_scn = 0

    Hi,
    After creating a local capture on the source database, and trying to start capturing, we could follow ist state changing in V$STREAMS_CAPTURE. After remaining a short time in the state "CAPTURING_CHANGE", the capture record disappears from the V$STREAMS_CAPTURE view.
    I tried to set the start_scn and first scn to values compatible with the most recent archived redolog on disk, but noticed that DBA_CAPTURE displays a value of 0 for the required_checkpoint_scn. I can't control this value - correct ?
    Any suggestion where I should look to find the cause of the problem ?
    Thanks in advance -
    Regards - Nicolas

    Hi Seankool - thanks for your input.
    We tried to run it, but it interrupts on the "select * from gv$rule"
    This bug has also been described in this thread
    gv$rule... hung  / core dumped
    So we will apply the fix described in # 369229.1. .... Time to get help from our DBA....
    Thanks and have a nice day

  • A problem with Threads and loops.

    Hi, I have some code that needs to be constantly running, like while(true)
          //code here
    }However, the code just checks to see if the user has input anything (and then if the user has, it goes to do some other stuff) so I don't need it constantly running and hogging up 98% of the CPU. So I made my class (which has the method that needs to be looped, call it ClassA) implement Runnable. Then I just added the method which needed to be looped into the public void run()
    I have another class which creates an instance of the above class (call it ClassB), and the main(String[] args) is in there.
    public static void main(String[] args)
              ClassA test = new ClassA();
              Thread thread = new Thread(test.getInstanceOfClassA());
              thread.start();
              while(true)
                           //I do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...) but I can't think of away to get it to run - sleep - run -sleep forever. Can someone help me?

    Hi, I have some code that needs to be constantly
    running, like while(true)
    //code here
    }However, the code just checks to see if the user has
    input anything (and then if the user has, it goes to
    do some other stuff) so I don't need it constantly
    running and hogging up 98% of the CPU. Where does the user input come from. Are you reading from an InputStream? If so, then your loop will be blocked anyway when reading from the InputStream until data is available. During that time, the loop will not consume processor cycles.
    public static void main(String[] args)
              ClassA test = new ClassA();
    Thread thread = new Thread(test.getInstanceOfClassA());I have never seen this idiom. If ClassA instanceof Runnable, you simply write new Thread(test).
              thread.start();
              while(true)
    //I do not know what to put
    do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...)Yeah, why would you want to call it more than once given that you have an infinite loop in ClassA.run()?
    Harald.
    Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software

  • A problem with Threads and MMapi

    I am tring to execute a class based on Game canvas.
    The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
    The MIDI tone "Stammers".
    How to over come the problem?
    Thanks in advance
    Kobi
    See Code example below:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    public class MainScreenCanvas extends GameCanvas implements Runnable {
         private MainMIDlet parent;
         private boolean mTrucking = false;
         Image imgBackgound = null;
         int imgBackgoundX = 0, imgBackgoundY = 0;
         Player player;
         public MainScreenCanvas(MainMIDlet parent)
              super(true);
              this.parent = parent;
              try
                   imgBackgound = Image.createImage("/images/area03_bkg0.png");
                   imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
                   imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
              catch(Exception e)
                   System.out.println(e.getMessage());
          * starts thread
         public void start()
              mTrucking = true;
              Thread t = new Thread(this);
              t.start();
          * stops thread
         public void stop()
              mTrucking = false;
         public void play()
              try
                   InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
                   player = Manager.createPlayer(is, "audio/midi");
                   player.setLoopCount(-1);
                   player.prefetch();
                   player.start();
              catch(Exception e)
                   System.out.println(e.getMessage());
         public void run()
              Graphics g = getGraphics();
              play();
              while (true)
                   tick();
                   input();
                   render(g);
          * responsible for object movements
         private void tick()
          * response to key input
         private void input()
              int keyStates = getKeyStates();
              if ((keyStates & LEFT_PRESSED) != 0)
                   imgBackgoundX++;
                   if (imgBackgoundX > 0)
                        imgBackgoundX = 0;
              if ((keyStates & RIGHT_PRESSED) != 0)
                   imgBackgoundX--;
                   if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
                        imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
          * Responsible for the drawing
          * @param g
         private void render(Graphics g)
              g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
              this.flushGraphics();
    }

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

  • Problem with Threads and "plase wait..."-Window

    Hi everyone,
    I have a problem that I'm not able to solve in any way... I have a time-consuming task (a file decryption) which I execute in a separate thread; I've used the SwingWorker class, like suggested by sun-tutorial, and it works right. The problem is that I have to wait that the decryption have finished before continuing with program-execution. Therefore I would like to display a "please wait"-window while the task runs. I've tryed all the possible ways I know but the problem is always the same: the waitWindow is displayed empty, the bounds are painted but the contents no; it's only painted when the decrypt-task has finished. Please help me, I have no more resources....
    decrypt-file code:
    public class DecryptFile {
      private String cryptedFileNameAndPath;
      private ByteArrayInputStream resultStream = null;
      // need for progress
      private int lengthOfTask;
      private int current = -1;
      private String statMessage;
      public DecryptFile(String encZipFileNameAndPath) {
        cryptedFileNameAndPath = encZipFileNameAndPath;
        //Compute length of task...
        // 0 for indeterminate
        lengthOfTask = 0;
      public ByteArrayInputStream getDecryptedInputStream() {
        return this.resultStream;
       * Called from ProgressBarDemo to start the task.
      public void go() {
        current = -1;
        final SwingWorker worker = new SwingWorker() {
          public Object construct() {
            return new ActualTask();
        worker.start();
       * Called from ProgressBarDemo to find out how much work needs
       * to be done.
      public int getLengthOfTask() {
        return lengthOfTask;
       * Called from ProgressBarDemo to find out how much has been done.
      public int getCurrent() {
        return current;
      public void stop() {
        current = lengthOfTask;
       * Called from ProgressBarDemo to find out if the task has completed.
      public boolean done() {
        if (current >= lengthOfTask)
          return true;
        else
          return false;
      public String getMessage() {
        return statMessage;
       * The actual long running task.  This runs in a SwingWorker thread.
      class ActualTask {
        ActualTask () {
          current = -1;
          statMessage = "";
          resultStream = AIUtil.getInputStreamFromEncZip(cryptedFileNameAndPath); //here the decryption happens
          current = 0;
          statMessage = "";
      }The code that calls decryption and displays waitWindow
          final WaitSplash wS = new WaitSplash("Please wait...");
          final DecryptFile cryptedTemplate = new DecryptFile (this.templateFile);
          cryptedTemplate.go();
          while (! cryptedTemplate.done()) {
            try {
              wait();
            } catch (Exception e) { }
          this.templateInputStream = cryptedTemplate.getDecryptedInputStream();
          wS.close();Thanks, thanks, thanks in advance!
    Edoardo

    Maybe you can try setting the priority of the long-running thread to be lower? so that the UI will be more responsive...

  • Problem with threads and graphics

    I have a thread that chooses paths for a Travelling salesman problem, it then calls a TSPdraw class and passes it the path, which the class then draws. the problem is when i have two threads it creates two windows but only draws a path in one of them. any ideas where i`m going wrong

    Are you using swing components? Swing isn't threadsafe. If you have multiple threads that want to update your UI you need to use the SwingUtilities.invokeLater(...)or invokeAndWait(...). There is a page in the swing tutorial about this at: http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

  • Problem with threads and ProgressMonitor

    Dear Friends:
    I have a little problem with a thread and a ProgressMonitor. I have a long time process that runs in a thread (the thread is in an separate class). The thread has a ProgressMonitor that works fine and shows the tasks progress.
    But I need deactivate the main class(the main class is the user interface) until the thread ends.
    I use something like this:
    LongTask myTask=new LongTask();
    myTask.start();
    myTask.join();
    Now, the main class waits for the task to end, but the progress monitor don`t works fine: it shows only the dialog but not the progress bar.
    What's wrong?

    Is the dialog a modal dialog? This can block other UI updates.
    In general, you should make sure that it isn't modal, and that your workThread has a fairly low priority so that the UI can do its updating

  • Problem with threads and/or memory

    I'm developing an application where there are 3 threads. One of them sends a request to the other, and if the 2nd can't answer it, it sends it to the 3rd (similar to CPU -> CACHE -> MEMORY). When i run the program with 1000-10.000 requests, no problem occurs. When i run it with 300.000-1.000.000 requests, it sometimes hangs. Is this a problem with the garbage collector, or should it be related to the threads mecanism.
    (note: eache thread is in execution using a finite state machine)

    i had been running the program inside Netbeans.
    Running the jar using the command line outside
    Netbeans i have no more problems... Does Netbeans use
    it's own JVM?Depends how you set it up, but look under the options. There are settings for the compiler and jvm that it uses.

Maybe you are looking for