0
你可以通過標題我的情況是瞭解:Grails的1.3.7 - 多租戶的插件和多線程運行 - 線程不能訪問租戶
- 我用一個很老的版本的Grails的(我此刻)
- 在這個項目中我使用多租戶的插件不能改變它,在細節我已經安裝了
- 多租戶核心:1.0.3
- 多租戶-的Ehcache: 1.0.1
- 我想拆分一個方法(需要2-3分鐘執行它)並行操作。
這裏是我的代碼:
def threadPoolSize = 10
def threadPool = Executors.newFixedThreadPool(threadPoolSize)
def threadClosure = { myWork ->
def partialQuantity = 0
myWork.each { currDetail ->
MyTableDomainClass.findByCode(currDetail.myTableCode)
// Do some stuff
}
return partialQuantity
}
try{
def worksForThreads = new ArrayList<org.codehaus.groovy.grails.web.json.JSONArray>(10)
// Prepare works for thread
Integer x = 0
allWorks.each{ singleOrder ->
if(worksForThreads[x] == null)
worksForThreads[x] = new org.codehaus.groovy.grails.web.json.JSONArray()
worksForThreads[x].add(singleOrder)
x = (x+1) % threadPoolSize
}
List<Future> futures = worksForThreads.collect({ myWork ->
println "\t\tPrepare thread with ${myWork.size()} tasks"
threadPool.submit({ ->
threadClosure myWork
} as Callable)
})
//Start thread and collect result
futures.each{
def threadResult = it.get()
println "\t\tThread result ${threadResult}"
totQuantity = totQuantity+threadResult
}
}catch(Exception e){
println "Error during thread works ${e}"
}finally{
threadPool.shutdown()
}
所以,代碼應該被罰款,但該線程的執行過程中,我得到這些錯誤:
[pool-9-thread-2] [tenant 0] ERROR util.JDBCExceptionReporter - Table 'MySchema.MyTable' doesn't exist
和
Error during thread works java.util.concurrent.ExecutionException: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query;
SQL [select this_.id as id24_0_, this_.code as code24_0_, this_.description as descript3_24_0_, this_.incr as incr24_0_, this_.is_default as is5_24_0_, this_.lang as lang24_0_, this_.last_updated as last7_24_0_, this_.min as min24_0_, this_.name as name24_0_, this_.ordasc as ordasc24_0_, this_.parent_id as parent11_24_0_, this_.parent_mult as parent12_24_0_, this_.prod_code as prod13_24_0_, this_.status as status24_0_, this_.unit_name as unit15_24_0_
from MyTable this_ where this_.code=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
我認爲問題出在租戶範圍之內。我想用一種服務來獲取數據庫中的所有數據,但我想知道是否有辦法在線程中獲得正確的租戶作用域或傳遞它。
謝謝大家!