SQL
Oracle
语句
最大值
排除字母,汉字,null,只取数字
select max(case when regexp_replace(MERCHAND_ID,'[0-9,.]', '') IS NULL then to_number(MERCHAND_ID) else 0 end) from SHWZ_DSH_RK_APPLY_MERCHAND
表被锁
--查询被锁的表
select b.owner,b.object_name,a.session_id,a.locked_mode from v$locked_object a,dba_objects b where b.object_id = a.object_id;
--查看是哪个session引起的
select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time;
--杀掉对应进程即解锁
alter system kill session '432,7303' --其中866是sid 20840是serial#
select pro.spid from v$session ses,v$process pro where ses.sid=971 and ses.paddr=pro.addr;
orakill orcl spid
MySql
线程
线程池
基本使用
对数据切割 动态使用线程 线程内部需要try
/**
* 插入数据
* @param attachFileInfos
* @param allMerchands
* @throws InterruptedException
*/
private void insertData(List<AttachFileInfo> attachFileInfos, List<ShwzDshRkApplyMerchand> allMerchands) throws InterruptedException
{
ExecutorService task = null;
if (attachFileInfos != null && !attachFileInfos.isEmpty())
{
int size = (int) Math.ceil(attachFileInfos.size() / 250.0);
if(size < 8){
size = 8;
}
List<List<AttachFileInfo>> fLists = ShwzDshShortUUIDUtil.averageAssign(attachFileInfos, size);
task = Executors.newFixedThreadPool(size);
for (List<AttachFileInfo> list : fLists)
{
task.execute(new Runnable()
{
@Override
public void run()
{
for (AttachFileInfo attachFileInfo : list)
{
attachFileClient.getAttachFileService().uploadAttachFile(attachFileInfo);
}
}
});
}
task.shutdown();
}
if (allMerchands != null && !allMerchands.isEmpty())
{
shwzDshRkApplyMerchandService.saveMerchands(allMerchands);
}
if (null != task)
{
while (true)
{
if (task.isTerminated())
{
break;
}
Thread.sleep(1000);
}
}
}