• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with stateless service  RSS feed

Tomasz Nawrot
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to write a simple file reader and got stuck.
I've got Spring app, one of the service is responsible for file access. The access is done via decorator MyFileReader.
One of the method from service is responsible for reading list of records and returning it as the list;
That service is injected to the second service in which all records are processed (code below)
The problem is that inside the method retrieveRecords I open the file, reads specifid number of records and close the file.
How to walk around this problem to allow method retrieveRecords to be called several times without closing the file since service should be stateless ?

view plaincopy to clipboardprint?

class MyServiceFile{
public List<Records> retrieveRecords(File file) throws MyException {
MyFileReader myFileReader = null;
try {
myFileReader = new MyFileReader(file);
return fileReader.readRecords(BUFFER_SIZE);

} finally {
if (myFileReader != null) {

class MyService{
MyServiceFile myServiceFile;

List<EcoRecord> recBuffer;
while ((recBuffer = ecotelFileService.retrieveIncomingCalls(cdrInFile))) {



  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!