Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4005a1

Browse files
author
zhourenjian@gmail.com
committed
On reloading class, try to pre-load class in given class loader to avoid being blocked on reading class bytes from disk
1 parent711b3a7 commita4005a1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleClassLoader.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ private byte[] loadClassData(String className) throws IOException {
131131
returnbuff;
132132
}
133133

134+
/**
135+
* Load given class.
136+
*
137+
* @param clazzName
138+
* @return
139+
*/
140+
publicstaticClass<?>loadSimpleClass(StringclazzName) {
141+
try {
142+
ClassLoaderclassLoader =hasClassReloaded ?allLoaders.get(clazzName) :null;
143+
if (classLoader !=null) {
144+
returnclassLoader.loadClass(clazzName);
145+
}else {
146+
returnClass.forName(clazzName);
147+
}
148+
}catch (Exceptione) {
149+
//e.printStackTrace();
150+
}
151+
returnnull;
152+
}
153+
134154
/**
135155
* Load given class and create instance by default constructor.
136156
*
@@ -225,6 +245,24 @@ public static void reloadSimpleClasses(String[] clazzNames, String path, String
225245
if (creatingMore) {// keep it in all loaders
226246
allLoaders.put("." + (checkedLoaders.size() +1),loader);
227247
}
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 (inti =0;i <clazzNames.length;i++) {
257+
Stringname =clazzNames[i];
258+
if (name !=null &&name.length() >0) {
259+
try {
260+
loader.loadClass(name);
261+
}catch (ClassNotFoundExceptione) {
262+
e.printStackTrace();
263+
}
264+
}
265+
}
228266
for (inti =0;i <clazzNames.length;i++) {
229267
Stringname =clazzNames[i];
230268
if (name !=null &&name.length() >0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp