@@ -43,7 +43,8 @@ public final class pdf2htmlEX {
4343 private String p_ownerPassword = "" ;
4444 private String p_userPassword = "" ;
4545
46- private boolean m_isNoForking = false ;
46+ private final static Object m_forkingSynchro = new Object ();
47+ private static boolean m_isNoForking = false ;
4748 private static boolean m_noForkingConversionAlreadyDone = false ;
4849
4950 public static class ConversionFailedException extends Exception {
@@ -113,20 +114,17 @@ public pdf2htmlEX setUserPassword(@NonNull String userPassword) {
113114 return this ;
114115 }
115116
116- public pdf2htmlEX setNoForking (boolean iDoUnderstandThatIWillHaveToRestartTheAppBeforeICanRunConversionForTheSecondTime ) throws IllegalArgumentException {
117+ public void setNoForking (boolean iDoUnderstandThatIWillHaveToRestartTheAppBeforeICanRunConversionForTheSecondTime ) throws IllegalArgumentException {
117118 if (!iDoUnderstandThatIWillHaveToRestartTheAppBeforeICanRunConversionForTheSecondTime ) {
118119 throw new IllegalArgumentException ();
119120 }
120- this .m_isNoForking = true ;
121- setNoForking ();
122- return this ;
121+ synchronized (m_forkingSynchro ) {
122+ m_isNoForking = true ;
123+ }
124+ set_no_forking ();
123125 }
124126
125127 public File convert () throws IOException , ConversionFailedException {
126- if (this .m_noForkingConversionAlreadyDone ) {
127- throw new ConversionFailedException ("No forking mode allows only one conversion!" );
128- }
129-
130128 if (null == this .p_inputPDF ) {
131129 throw new ConversionFailedException ("No Input PDF given!" );
132130 }
@@ -135,6 +133,12 @@ public File convert() throws IOException, ConversionFailedException {
135133 throw new ConversionFailedException ("Input PDF does not exist!" );
136134 }
137135
136+ synchronized (m_forkingSynchro ) {
137+ if (m_noForkingConversionAlreadyDone ) {
138+ throw new ConversionFailedException ("No forking mode allows only one conversion!" );
139+ }
140+ m_noForkingConversionAlreadyDone = m_isNoForking ;
141+ }
138142 String inputFilenameNoPDFExt = this .p_inputPDF .getName ();
139143 if (inputFilenameNoPDFExt .endsWith (".pdf" )) {
140144 inputFilenameNoPDFExt = inputFilenameNoPDFExt .substring (0 , inputFilenameNoPDFExt .length () - 4 );
@@ -149,11 +153,7 @@ public File convert() throws IOException, ConversionFailedException {
149153 m_poppler_dataDir .getAbsolutePath (), m_pdf2htmlEX_tmpDir .getAbsolutePath (),
150154 this .p_inputPDF .getAbsolutePath (), outputHtml .getAbsolutePath (),
151155 this .p_ownerPassword , this .p_userPassword
152- );
153-
154- if (this .m_isNoForking ) {
155- this .m_noForkingConversionAlreadyDone = true ;
156- }
156+ );
157157
158158 if (0 != retVal ) {
159159 outputHtml .delete ();
@@ -168,5 +168,5 @@ public File convert() throws IOException, ConversionFailedException {
168168 // Because Java cannot setenv for the current process
169169 static native void set_environment_value (String key , String value );
170170
171- private native void setNoForking ();
171+ private native static void set_no_forking ();
172172}
0 commit comments