multithreading - How to improve Java performace using static variables and threads? -
for sake of not going deep software supposed let me give example of trying solve, make short , sweet.
lets have base class called x , implementation of class, call y. class y, naturally, extends base class x. lets have 20 objects instantiating class y via separate thread each object , every instantiation big file loaded memory. of these objects, perhaps, might need use different files make simple, lets need access same file.
is there way define object(variable) points these files statically in base class that, though implementation class loaded 20 times via 20 different threads, can share same static object, file needs loaded 1 time???
thanks in advance...
if know file ahead of time, open , load file in static initializer block, , store contents in static data member. content accessible instances of class, regardless of thread accessing instance objects.
// in base class protected static final string filecontents; static { filecontents = readstufffromfile(); }
Comments
Post a Comment