/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.evolute.dbtransfer.transfer;

import java.util.List;

/**
 *
 * @author lflores
 */
public class ReportThread extends Thread
{
    private static final int SLEEP_TIME_MS = 5000;
    
    private final Mover mover;
    private final List<AsyncStatement> threads;
    
    private boolean running = true;
    
    public ReportThread( Mover mov, List<AsyncStatement> list )
    {
        mover = mov;
        threads = list;
        setDaemon( true );
    }
    
    @Override
    public void run()
    {
        int lastRead = 0;
        while( running || !threads.isEmpty() )
        {
            System.out.println();
            if( !running )
            {
                System.out.println( "WAITING WRITES" );
            }
            int r = mover.getReadCount();
            System.out.println( "READ: " + ( r - lastRead ) 
                    + " in " + SLEEP_TIME_MS + "ms sleeping: " + mover.isSleeping() );
            lastRead = r;
            if( threads.size() > 1 )
            {
                System.out.println( "WRITING THREADS: " + threads.size() );
            }
            for( AsyncStatement as: threads )
            {
                System.out.println( "WRITE: id: " + as.getName() + " rows: " 
                        + as.getAndResetWriteRows() + " in " + SLEEP_TIME_MS + "ms " 
                        + ( as.isSleeping()? "sleeping!": "" )
                        + " shared rows: " + as.getSharedRowsSize()
                        + " private rows: " + as.getPrivateRowsSize());
            }
            try
            {
                sleep( SLEEP_TIME_MS );
            }
            catch( InterruptedException ex )
            {
            }
        }
    }
    
    public void stopReporting()
    {
        running = false;
    }
}

@@ -1330,32 +1330,91 @@
 )%0A            %7B%0A
+                int privateRows = as.getPrivateRowsSize();%0A
                 
@@ -1471,24 +1471,24 @@
  %22 rows: %22 %0A
-
             
@@ -1742,33 +1742,410 @@
 %22 + 
-as.getPrivateRowsSize());
+privateRows );%0A                if( privateRows == 0)%0A                %7B%0A                    long totalMem = Runtime.getRuntime().totalMemory();%0A                    long freeMem = Runtime.getRuntime().freeMemory();%0A                    System.out.println( %22free: %22 + freeMem / (1024*1024) %0A                        + %22/%22 + totalMem / (1024*1024) + %22MB%22 );%0A                    System.gc();%0A                %7D
 %0A   

improve output