Grails CSV Plugin - Concurrency -


i using plugin: grails csv plugin in application grails 2.5.3. need implement concurrency functionality example: gpars, don't know how can it.

now, configuration sequential processing. example of code fragment:

thanks.

implementing concurrency in case may not give of benefit. depends on bottleneck is. example, if bottleneck in reading csv file, there little advantage because file can read in sequential order. out of way, here's simplest example come with:

import groovyx.gpars.gparspool  def tokens = csvfileload.inputstream.tocsvreader(['separatorchar': ';', 'charset': 'utf-8', 'skiplines': 1]).readall() def failedsaves = gparspool.withpool {     tokens.parallel         .map { it[0].trim() }         .filter { !department.findbyname(it) }         .map { new department(name: it) }         .map { customimportservice.saverecordcsvdepartment(it) }         .map { ? 0 : 1 }         .sum()  }  if(failedsaves > 0) transactionstatus.setrollbackonly() 

as can see, entire file read first; hence main bottleneck. majority of processing done concurrently map(), filter(), , sum() methods. @ end, transaction rolled if of departments failed save.

note: chose go map()-sum() pair instead of using anyparallel() avoid having convert parallel array produced map() regular groovy collection, perform anyparallel(), creates parallel array , converts groovy collection.

improvements

as mentioned in example csv file first read before concurrent execution begins. attempts save of department instances, if 1 failed save. may want (which demonstrated) or not.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -