Bonjour à tous
J'ai à alimenter une base de données via un programme Java.
Pour ce programme, j'ai utilisé Spring et Hibernate, et j'ai dû m'essayer à faire des Thread (1ère fois que j'en fais).
J'ai utilisé Executor (du package java.util.concurrent) car on me demande de faire un programme optimisé et rapide.
J'utilise un pool de thread.
Le programme fonctionne bien, pendant environ 45 secondes et après, j'obtiens cette erreur répétée plusieurs fois :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 Exception in thread "pool-1-thread-593" org.hibernate.exception.JDBCConnectionException: Cannot open connection at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1463) at fr.msa.agora.bp0gos.qualification.structure.InjecteurFluxStructureRFOSImpl$UnitOfWork.run(InjecteurFluxStructureRFOSImpl.java:107) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: java.sql.SQLException: socket creation error at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source) at org.hsqldb.jdbcDriver.getConnection(Unknown Source) at org.hsqldb.jdbcDriver.connect(Unknown Source) at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
Voici une partie de mon code :
Merci d'avance à vous tous,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @Service("InjecteurStructure") public class InjecteurFluxStructureRFOSImpl extends AbstractInjecteurFluxRFOS implements InjecteurFluxRFOS { private final StructureRFOS2StructureGOSMapperImpl mapper; @Autowired public InjecteurFluxStructureRFOSImpl(final StructureRFOS2StructureGOSMapperImpl pMapper, final SessionFactory pSession, final Executor pPoolDeThread, final GestionRepertoire pGestionRepertoire) { super(pSession, pPoolDeThread, pGestionRepertoire); mapper = pMapper; } @Override public void mapUnFichier(final File pFichier) { final RFOSStructure structureFichier = JAXB.unmarshal(pFichier, RFOSStructure.class); persisterTable(structureFichier.getSTS()); } private void persisterTable(final STS pStructureSTS) { final UnitOfWork unit = new UnitOfWork(mapper, sessionFactory, pStructureSTS); poolDeThread.execute(unit); } private static class UnitOfWork implements Runnable { private final StructureRFOS2StructureGOSMapperImpl mapper; private final SessionFactory sessionFactory; private final STS structureSTS; public UnitOfWork(final StructureRFOS2StructureGOSMapperImpl pMapper, final SessionFactory pSession, final STS pStructureSTS) { mapper = pMapper; sessionFactory = pSession; structureSTS = pStructureSTS; } /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ @Override public void run() { final Session session = sessionFactory.openSession(); try { final fr.msa.agora.bp0gos.metier.sts.domaine.STS structureGOS = mapper.map(structureSTS); final Transaction transaction = session.beginTransaction(); try { session.save(structureGOS); session.flush(); transaction.commit(); } catch (final RuntimeException r) { transaction.rollback(); throw r; } catch (final Error error) { transaction.rollback(); throw error; } } finally { session.close(); } } } }
Thomas
PS: La volumétrie est d'environ 90000 fichiers à parser, afin d'alimenter la base de données.
Partager