Concurrency with scala.sys.process.ProcessBuilder -


i'm using spdf's run method render html pdf file.

run uses scala.sys.process.processbuilder , it's ! method:

/** starts process represented builder, blocks until exits, ,     * returns exit code.  standard output , error sent console.     */   def ! : int 

my controller using future asynchronously execute conversion won't spdf block other interim executions?

 future { pdf.run(sourceurl, outputstream) } map { exitcode =>      outputsteam.tobytearray  } 

update

thanks answer paul did little test , yeah looks way :)

if update spdf's run so:

  def run[a, b](sourcedocument: a, destinationdocument: b)(implicit sourcedocumentlike: sourcedocumentlike[a], destinationdocumentlike: destinationdocumentlike[b]): int = {       println("start/ " + system.currenttimemillis)       < ... code removed ... >       val result = (sink compose source)(process).!       println("finish/ " + system.currenttimemillis)       result   } 

and execute 3 consecutive requests stdout prints

start 1461288779013 start 1461288779014 start 1461288779014 finish 1461288781018 finish 1461288781020 finish 1461288781020 

which looks asynchronous execution.

this pdf#run:

  def run[a, b](sourcedocument: a, destinationdocument: b)(implicit sourcedocumentlike: sourcedocumentlike[a], destinationdocumentlike: destinationdocumentlike[b]): int = {     val commandline = tocommandline(sourcedocument, destinationdocument)     val process = process(commandline)     def source = sourcedocumentlike.sourcefrom(sourcedocument) _     def sink = destinationdocumentlike.sinkto(destinationdocument) _      (sink compose source)(process).!   } 

there's no synchronization prevents parallel execution. assuming executioncontext has enough available threads,

future { pdf.run(sourceurl, outputstream) } map { exitcode =>     outputsteam.tobytearray }  future { pdf.run(sourceurl, outputstream) } map { exitcode =>     outputsteam.tobytearray } 

will execute in parallel.


if instead, run method had been, say, surrounded synchronized block, 1 invocation execute per pdf instance. there's no reason prevent concurrency here, author didn't.


Comments

Popular posts from this blog

Why does Go error when trying to marshal this JSON? -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

python - Pygame. TypeError: 'pygame.Surface' object is not callable -