Hi,

It is a known behavior of Windows that if you interrupt a thread that is
currently writing using a FileChannel, that the file is closed. This has
been found in other projects as well, for example Apache Lucene and Apache
Jackrabbit:

http://jackrabbit.510166.n4.nabble.com/jira-Created-JCR-3469-Thread-interrupt-may-result-in-closed-index-files-td4657049.html

http://stackoverflow.com/questions/3541411/closedbyinterruptexception-not-thrown

http://bugs.sun.com/view_bug.do?bug_id=6979009

One solution is to *not* interrupt the thread. Another is to *not* use NIO,
at least under Windows.

Regards,
Thomas


On Tue, May 14, 2013 at 6:53 PM, abhinav mehrotra <
[email protected]> wrote:

>
> I am getting following exception on killing the thread. The exception
> comes when *"nio" (dbc:h2:nio:test)* is used while creating the
> connection. However, without "nio" there is no exception.
>
> Also, once this exception occurs DB is corrupted and is not able to
> recover on restart.
>
> org.h2.jdbc.JdbcSQLException: IO Exception:
> "java.nio.channels.ClosedChannelException"; "nio:test.h2.db" [90031-147]
>
>     at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
>     at org.h2.message.DbException.get(DbException.java:156)
>     at org.h2.message.DbException.convertIOException(DbException.java:313)
>     at org.h2.store.FileStore.write(FileStore.java:342)
>     at org.h2.store.PageStore.writePage(PageStore.java:1309)
>     at org.h2.store.PageStreamData.write(PageStreamData.java:105)
>     at org.h2.store.PageOutputStream.storePage(PageOutputStream.java:148)
>     at org.h2.store.PageOutputStream.write(PageOutputStream.java:130)
>     at org.h2.store.PageLog.write(PageLog.java:529)
>     at org.h2.store.PageLog.commit(PageLog.java:549)
>     at org.h2.store.PageStore.commit(PageStore.java:1417)
>     at org.h2.engine.Database.commit(Database.java:1685)
>     at org.h2.engine.Session.commit(Session.java:459)
>     at org.h2.command.Command.stop(Command.java:170)
>     at org.h2.command.Command.executeUpdate(Command.java:250)
>     at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
>     at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)
>     at testH2.insert(testH2.java:33)
>     at testH2$1.run(testH2.java:43)
>     at java.lang.Thread.run(Thread.java:722)
>
> Following is the sample program:
>
>
> public class testH2 {
>     static Connection conn = null;
>     static  PreparedStatement statP = null;
>     static{
>            try {
>             Class.forName("org.h2.Driver");
>             conn = DriverManager.getConnection("jdbc:h2:nio:test");
>
>             statP = conn.prepareStatement("insert into test1 values(1,
> 'Hello')");
>         } catch (ClassNotFoundException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (SQLException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>
>     }
>
>     public void insert() throws SQLException{
>         statP.executeUpdate();
>     }
>
>     public static void main(String... args) throws Exception {
>
>        Thread t =  new Thread(new Runnable(){
>             public void run(){
>                 testH2 t = new testH2();
>                 for (int i=0;i<50000;i++){
>                     try {
>                         t.insert();
>                     } catch (SQLException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                     }
>                 }
>             }
>         }
>         );
>        t.start();
>        Thread.sleep(1);
>        t.interrupt();
>        testH2 tx = new testH2();
>        tx.insert();
>
>
>     }
> }
>
> Any references or pointers would be highly appreciated.
>
> Thanks in advance
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/h2-database?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to