Run hashtable, memory how to do?

Category: Java SE
 
liudi87
2010-05-10 11:44:14

Sponsored Links
I wrote a program, nothing to do with the Kazakh Cynoglossidae search, is said to run out of memory, how to do?


Sponsored Links

benpao180
2010-05-11 12:10:27
hashtable do a search using
a3029111
2010-05-11 12:36:45
say clearly, so who knows what you do with the hashtable which part ah?
store results?
guhaiyizhoulaile
2010-05-11 01:09:31
is not placed in a large number of objects?
tannet
2010-05-11 01:39:07
insufficient memory to show that you have created too many objects chant, to solve this problem, do not create too many objects chant.

hehe
qinghuaxiaoyouboke
2010-05-11 02:12:35
Option 1: increase the JVM memory (of course only if you really have that much RAM)
Method 2: Change the algorithm
sg3010
2010-05-11 02:36:15
I have a table in the database content into a hashtable, in the process, there are a data table updates and additions. Look at the table program is new, there are no programs to generate object, if there is to update, did not add! Add me to about 50,000 objects when enough memory. There is no good way to solve this problem ah!
cuitaoaa
2010-05-11 03:10:49
private static Hashtable W_table = new Hashtable ();

private static Hashtable P_table = new Hashtable ();

/ / construct the hash table
private static void ConstructTable () {
String word = new String ();
byte Aword [] = null;
; ResultSet rs = null;
Statement stm1 = null;
Connection con1 = null;

int t = 0;
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DATABASE_URL = "jdbc: mysql :/ / localhost / wordbase ";
int c = 0;

try {

Class.forName (JDBC_DRIVER);
; con1 = DriverManager.getConnection (DATABASE_URL, "root", "root");
; stm1 = con1.createStatement ();

/ / construct w_table
; rs = stm1.executeQuery ("SELECT * FROM worddatas");
; rs.beforeFirst ();
while (rs.next ()) {

t = rs.getInt (4);
/ / System.out.println (Aword);
; W_table.put (rs.getString (3), new Integer (t));
/ / System.out.println ((String) W_table.get (Aword));
/ / i + +;
;
}
System.out.println (c);
; System.out.println (W_table.size ());
rs = stm1.executeQuery ("SELECT * FROM Probability_c");
rs.beforeFirst ( );
while (rs.next ()) {
; Vector vc = new Vector ();
vc.add (0, (String) rs.getString (1));
; vc.add (1, (String) rs.getString (2));
vc.add (2, new Integer (rs.getInt (4)));
; vc.add (3, new Integer (0));
; P_table.put (rs.getString (3), vc);
; / / P_table.put (rs.getString (3), new Integer (t) );
}
;
/ / System.out.println (i);
con1.close ();
}

catch (Exception ; e) {
System.out.println (e + "in table construct");
System.exit (1);
}

}
guoqing300
2010-05-11 03:26:39
private static void CollectWordPair (String artical, String Char8xxFile) {
int i, j, k;
int ; l = 0;
int j1, j2, j3;
int flag = 0;
char Char8xx [] = new ; char [1000];

int NumberOfRead = -1;
File InputFile = new File (artical);
FileReader InWord = null;
File CharFile = new File ( Char8xxFile);
FileReader InChar = null;
char Line [] = new char [8192];
String Sentence = new String ( );
StringBuffer Sen_NoString = new StringBuffer ();
;
StringBuffer Sen = new StringBuffer ();
String [] phrase = new String [8192];
String CharNoString = new String ();

/ / read in char file
try {
; InChar = new FileReader (CharFile);
InChar.read (Char8xx);
/ / System.out.println ("read char file success");

}
; catch (FileNotFoundException e) {
System. out.println ("Char File Not Found");
System.exit (1) ;
}
catch (Exception e) {
System.out.println ("error during read char ; file ");
System.exit (1);
}

try
{
InWord = new FileReader (InputFile);

;}

catch (FileNotFoundException e) {
System . out.println (e);

}

int a = 0;
/ / read in passage line by line to check, till it is over!
do {
/ / read in a line
try {
; / / System.out.println ("read artical ; file success ");
NumberOfRead = InWord.read (Line);
;}
catch (Exception e) {
; System.out.println ("error during read char file");
; System.exit (1);
}

;
; for (i = 0; i <8192; i + +) {
if ((Line [i]! = '\ n')) {
Sen.append (Line [ i]);

}

; else {
;
; / / System.out.println ("sentence contrust success");
/ / change the ; sentence char to no_string for the ease of sql process
l = 0;
; for (k = 0; k <Sen.length (); k + +) {
for (j = 0; j <1000; j + +) {
; if (Sen.charAt (k) == Char8xx [j]) {
; / / System.out.println (Sen.charAt (k));
; ; j1 = j/100;
j2 = ; (j - 100 * j1) / 10;
; j3 = j - 100 ; * j1 - 10 * j2;
Sen_NoString.append (j1);
; Sen_NoString.append (j2);
Sen_NoString.append (j3);
; ; Sen_NoString.append ('$');
break;
}
;
;}
if (j == 1000) Sen_NoString.append ("# # # $ ");
}
/ / System.out.println (Sen_NoString.toString ());
/ / System.out.println (Sen_NoString.length ());
; k = 0;
while (k <Sen_NoString.length ()) {
; ; CharNoString = Sen_NoString.substring (k, k +4);
; if (CharNoString.equalsIgnoreCase ("# # # $")) {

k = k + 4;

}
; else {
;
; for (j = k +4 ; j <Sen_NoString.length (); j = j +4) {
CharNoString = Sen_NoString.substring (j, j +4);
if (CharNoString.equalsIgnoreCase ("# # # $" )) {
;
; ; phrase [l + +] = Sen_NoString.substring (k, j);
; ; / / System.out.println (phrase [l-1]);
; ; / / System.out.println (l-1);
k = j + 4;

break;
}
;
;}
}
;
;}
/ / System.out.println ( "change to NoString success");
Sen.delete (0, Sen.length ());
; Sen_NoString.delete (0, Sen_NoString.length ());

/ / Start collect word-pairs
; for (j = 0; j < ; l; j + +) {
/ / System.out.println (phrase [j]);
doCollectProcess (phrase [j]);
}
; System.out.println (a + +);
}
;
;}

} while (NumberOfRead == 8192);

}
zou0520
2010-05-11 03:51:37
reduce reuse
zhouqi123321
2010-05-11 04:14:07
Can explain in detail ah !
gfdhfh
2010-05-11 04:52:33
put too much may cause memory overflow, if you really think this way,
can consider a fat count, such hashTable 1000 rows in the first table data
put , the algorithm for more, such as the most recently used, recently used and so on. . .

wjzhanghao21
2010-05-11 05:20:34
I think you might as well turn thought it made changes into a data structure, when ready to update the changed data when updating
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.