@@ -131,6 +131,26 @@ private byte[] loadClassData(String className) throws IOException {
131
131
return buff ;
132
132
}
133
133
134
+ /**
135
+ * Load given class.
136
+ *
137
+ * @param clazzName
138
+ * @return
139
+ */
140
+ public static Class <?> loadSimpleClass (String clazzName ) {
141
+ try {
142
+ ClassLoader classLoader = hasClassReloaded ? allLoaders .get (clazzName ) : null ;
143
+ if (classLoader != null ) {
144
+ return classLoader .loadClass (clazzName );
145
+ } else {
146
+ return Class .forName (clazzName );
147
+ }
148
+ } catch (Exception e ) {
149
+ //e.printStackTrace();
150
+ }
151
+ return null ;
152
+ }
153
+
134
154
/**
135
155
* Load given class and create instance by default constructor.
136
156
*
@@ -225,6 +245,24 @@ public static void reloadSimpleClasses(String[] clazzNames, String path, String
225
245
if (creatingMore ) { // keep it in all loaders
226
246
allLoaders .put ("." + (checkedLoaders .size () + 1 ), loader );
227
247
}
248
+ /*
249
+ * It is important to pre-load classes. On server with
250
+ * heavy traffic, If classes are not not being pre-
251
+ * loaded, later reading class bytes from disk (IO) may
252
+ * cause lots of threads from thread pool hanging for
253
+ * some milliseconds, and threads are eaten up, and
254
+ * server may be down in seconds!
255
+ */
256
+ for (int i = 0 ; i < clazzNames .length ; i ++) {
257
+ String name = clazzNames [i ];
258
+ if (name != null && name .length () > 0 ) {
259
+ try {
260
+ loader .loadClass (name );
261
+ } catch (ClassNotFoundException e ) {
262
+ e .printStackTrace ();
263
+ }
264
+ }
265
+ }
228
266
for (int i = 0 ; i < clazzNames .length ; i ++) {
229
267
String name = clazzNames [i ];
230
268
if (name != null && name .length () > 0 ) {
0 commit comments