Skip to content

Instantly share code, notes, and snippets.

@edgargs
Created April 26, 2018 20:24
Show Gist options
  • Save edgargs/938f69d7d945cf09df8eafbd9cde1094 to your computer and use it in GitHub Desktop.
Save edgargs/938f69d7d945cf09df8eafbd9cde1094 to your computer and use it in GitHub Desktop.
@Grapes([
@Grab(group='com.microsoft.sqlserver', module='sqljdbc4', version='4.0'),
@GrabConfig(systemClassLoader = true),
@Grab(group='org.codehaus.gpars', module='gpars', version='1.2.1')
])
import groovy.sql.Sql
import groovyx.gpars.GParsExecutorsPool
import groovy.transform.Field
def callProcedure() {
def con = Sql.newInstance("jdbc:sqlserver://B200603SV527\\SQLBCO2012;databaseName=Canales_DESA","_CORE_CHANNELS_VB_APP","Lima\$2017","com.microsoft.sqlserver.jdbc.SQLServerDriver")
con.call("EXEC SPP_HBK_TRACE_CANAL ?,?,?",[5,'ADN',Sql.INTEGER]) {
P_SECUENCIA -> println "$P_SECUENCIA " + (new Date())
}
con.close()
}
def sendItems(items) {
GParsExecutorsPool.withPool(10) {
items.eachParallel { num ->
println "in closure $num " + epoch()
this.sleep 5*1000
//callProcedure()
//myClosure num
}
}
}
def lista = [] as List<Integer>
lista.addAll(1..30)
sendItems(lista)
long epoch() {
now = Calendar.instance
//println 'now is a ' + now.class.name
date = now.time
epoch1 = date.time
return epoch1/1000
}
@Field
def myClosure = {num ->
while(true) {
def timenow = epoch()
def speed = Math.abs(new Random().nextInt() % 80)
println "Client DCS [${num}]: time=${timenow} speed=${speed}"
sleep(tiempo*1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment