나는 100 항목이 특정 테이블 열 항목을 업데이 트해야합니다 동적으로 업데이 트가 필요합니다 DB가 있습니다. 기본적으로 모든 100 개 항목DB를 업데이 트하는 자바 멀티 스레드 응용 프로그램
는 디스크 에서 데이터를 수집하고 그들이 while 루프에서 잠금을 얻을 때까지 시도 잠금을 얻을 수있는 DB를/디스크 정보를 얻을 수있는 DB tables.In 순서를 업데이트합니다. 일단 잠금을 얻으면 최신 디스크 정보 만 DB로 업데이트 할 수 있습니다.
본질적으로 위의 작업을 순차적으로 수행하는 다음 페도수 코드가 있습니다. 병렬 작업을 수행 할 수 있도록 다중 스레드 방식으로 실행하려고합니다. 제발 나를 안내해 주시겠습니까? 나는 자바 멀티 스레드 프로그램에 완전히 익숙하지 않습니다.
감사의 말을 전합니다.
while(true)
{
for(int i=0,i<100;i++)
{
//Get the info from Disk
String diskInfo=getDiskInfo(i);
//Get the info from DB table
String dbInfo=getDBInfo(i);
if (! diskInfo.equals(dbInfo))
{
//Update DB with diskInfo
boolean status=UpdateDB(i);
}
}
sleep(2000);
}
//Get the info from Disk
public String getDiskInfo()
{
//Get the disk
//lock the disk wait if busy
while(true)
{
//get disk lock
sleep(2000);
}
//fetch data
String data = "test";
//unlock disk
return data;
}
public String getDBInfo()
{
//Get the DB
//lock the DB wait if busy
while(true)
{
//get DB lock
sleep(2000);
}
//fetch data
//select data from X;
String data = "test";
//unlock disk
return data;
}
public boolean UpdateDB()
{
//Get the DB
//lock the DB wait if busy
while(true)
{
//get DB lock
sleep(2000);
}
//fetch data
if(!getDiskInfo(),equals(getDBInfo())
{
//lock the DB wait if busy
while(true)
{
//get DB lock
sleep(2000);
}
status=UpdateDB();
}
else
{
//no update needed
status=false;
}
return status;
}