FileChannel.Force (True)가 예외를 던졌습니다.
-
20-12-2019 - |
문제
filechannel을 호출 할 때 무슨 일이 일어나고 예외를 던 졌을 때?
filechannel.write가 성공했을 때 우리는 모든 것이 디스크로 씻어 졌는지 확인하려는 FileChannel에 전체 버퍼 컨텐츠를 쓸 수있었습니다.나는 예외를 던질 수있는 힘을 부르겠습니다 (true).내가 FileChannel에 쓴 데이터로 어떤 일이 일어나는가?디스크로 플러시되거나 데이터의 일부가 플러시 될 수있는 것은 없습니다.작동을 어떻게 롤백 할 수 있습니까?
public boolean flush(ByteBuffer[] buffers, long buffersRemaining)
{
try
{
FileChannel fileChannel = new RandomAccessFile(target, "rw").getChannel();
long writtenBytes = fileChannel.write(buffers);
//we think we have written all the data into filechannel
if(writtenBytes == buffersRemaining)
{
//we try to flush, but we get an exception
try
{
fileChannel.force(true);
fileChannel.close();
}
catch(IOException exception)
{
//???
return false;
}
}
}
catch(Exception exception)
{
//log exception
return false;
}
}
. 해결책
사용자가 뭔가를 할 수 있다면 예외를 처리하려고 시도해야합니다.이것이 의미가없는이 경우 중 하나입니다.이것은 정상적으로 발생하지 않아야하며 예외를 기록하고 정상적으로 실패합니다.
제휴하지 않습니다 StackOverflow