Re: Issue on multi-threaded page when opening another tab in browser

2014-02-19 Thread eaglei22
Hi Martin,

I originally had the List as an instance variable for the Page but when I
would open a new browser tab, the original page would crash and a
nullpointerException would be given because the page reference lost
reference to the object. 

So now I create in the page constructor in instance of BatchLines and pass
it along through method parameters. 

The thread is started from a method called in the constructor. Here is the
def of this method:

/
 * Method: beginProcessing
 * 
 * Invokes workerThreads 
 * 
 * returns: void
 /
private void beginProcessing(List batchLines)
{
  fullReportDwnLoadBtn.setVisible(false);
  
  try
  {
  csvFileCreater = new CSVFileCreater(LOADER_CSV_FILE_NAME);
  if(turnOnLoader)
  {
BatchLoaderProcessingThread threadJob = new
BatchLoaderProcessingThread(stringList, batchLines);
loggerThread = new Thread(threadJob);
loggerThread.start();
  }
  else
  {
BatchDeleteProcessingThread deleterThreadJob = new
BatchDeleteProcessingThread(stringList, batchLines);
loggerThread = new Thread(deleterThreadJob);
loggerThread.start(); 
  }
  } catch (IOException e)
  {
// TODO Auto-generated catch block
log.error(Inside beginProcessing() throws error:  + 
e.toString());
BatchProcessPage.this.error(An error has occurred 
starting creation of
CSV file);
  }
}

Here is the definition of the thread class:

class BatchLoaderProcessingThread implements Runnable
{
List stringList;
List batchLines;
public BatchLoaderProcessingThread(List stringList, List batchLines) 
{
this.batchLines = batchLines;
this.stringList = stringList;
}

@Override
public void run()
{
processLine(stringList, batchLines);
loaderFinished();
}   
}   


processLine is a method that is part of the Page class. 


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-on-multi-threaded-page-when-opening-another-tab-in-browser-tp4664552p4664570.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Issue on multi-threaded page when opening another tab in browser

2014-02-19 Thread eaglei22
I fixed this issue by making my runnable class serializable and putting a
reference to the Thread inside there and also the list. This seemed to fix
this issue. 

Thanks for your time Martin. 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-on-multi-threaded-page-when-opening-another-tab-in-browser-tp4664552p4664575.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Issue on multi-threaded page when opening another tab in browser

2014-02-19 Thread eaglei22
Nvm, it's still doing it. 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-on-multi-threaded-page-when-opening-another-tab-in-browser-tp4664552p4664576.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Issue on multi-threaded page when opening another tab in browser

2014-02-18 Thread eaglei22
Okay, so I have an issue that I have finally narrowed down to multi-threading
issues. 

I have a loader page that has a worker thread to process a csv file and
store the results into a list declared as:

List batchLines = Collections.synchronizedList(new
CopyOnWriteArrayListBatchLine());

Each BatchLine object is a row in the csv file that was processed. 


I also have a pageableListView on the page that uses the BatchLine List to
update itself. I use a 
AjaxSelfUpdatingTimerBehavior which will update the pageableListView every
two seconds.  The problem is, if I am on this page in one browser tab, and
the workerthread is running, and the page is updating, and then at the same
time I open another instance of the application in another tab of the same
browser, the thread loses focus of this List. I know this because I print
out the size of the list, and it stays the same when I open a new instance. 

I first had the List batchLines Global, but now I pass it as a parameter to
keep it local to each method. When it was global, I had to mark it transient
for serializable issues. The issue with this is the page would crash when I
opened a new tab with another instance of the application. 

What can I do to prevent this? 



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-on-multi-threaded-page-when-opening-another-tab-in-browser-tp4664552.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Issue on multi-threaded page when opening another tab in browser

2014-02-18 Thread Martin Grigorov
Hi,


On Wed, Feb 19, 2014 at 3:23 AM, eaglei22 jchojnack...@gmail.com wrote:

 Okay, so I have an issue that I have finally narrowed down to
 multi-threading
 issues.

 I have a loader page that has a worker thread to process a csv file and
 store the results into a list declared as:

 List batchLines = Collections.synchronizedList(new
 CopyOnWriteArrayListBatchLine());


Where is declared this list ?
I.e. who keeps the reference to it ?
Also how do you start the Thread ?



 Each BatchLine object is a row in the csv file that was processed.


 I also have a pageableListView on the page that uses the BatchLine List to
 update itself. I use a
 AjaxSelfUpdatingTimerBehavior which will update the pageableListView every
 two seconds.  The problem is, if I am on this page in one browser tab, and
 the workerthread is running, and the page is updating, and then at the same
 time I open another instance of the application in another tab of the same
 browser, the thread loses focus of this List. I know this because I print
 out the size of the list, and it stays the same when I open a new instance.

 I first had the List batchLines Global, but now I pass it as a parameter to
 keep it local to each method. When it was global, I had to mark it
 transient
 for serializable issues. The issue with this is the page would crash when I
 opened a new tab with another instance of the application.

 What can I do to prevent this?



 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/Issue-on-multi-threaded-page-when-opening-another-tab-in-browser-tp4664552.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org