-5

I am working on a service in which I have to perform some events, log them and return the results. I want that user should not wait for logging to complete, and therefore should get immediate results whereas logging can continue. Any suggestions on these?

a()
b()
.
.
.
g()//all these function are required to compute somethings which user wants
logging() //it takes time
return results
Akashdeep Saluja
  • 2,959
  • 8
  • 30
  • 60
  • What framework you are using, what solution you have tried, is it desktop or web application? – HRgiger Aug 28 '15 at 06:16
  • 1
    you can submit your logging as a separate task to another thread (or an executor service, which returns the control immediately) – user1933888 Aug 28 '15 at 06:25

1 Answers1

1

If logging is an overhead for you, and you want that to be an asynchronous process, then there are definitely ways to achieve this:

  1. You can create your own handlers to do this, i.e create a FIFO queue to submit all your log strings and another process can read and print these messages as a separate process, so in your original flow you only add the log message to queue and move ahead, of course this involves reinventing the wheel, but you have the freedom to do exactly what you need for your project. You may want to look at this answer
  2. You can leverage existing framework, like log4j, which provides many options to achieve async logging using specific async appenders. You can find details about it here
Community
  • 1
  • 1
user1933888
  • 2,897
  • 3
  • 27
  • 36