hej mam coś takiego
plik main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package forex;
import java.util.Timer;
/**
*
* @author daro
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Forex f = new Forex();
if ( f.init() == 0)
{
Timer t = new Timer();
t.schedule(f,1 * 1000, 1 * 1000);
f.close();
}
}
}
i plik Forex.java
package forex;
import java.io.DataInputStream;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Forex extends TimerTask {
private Connection con;
private static Logger logger = Logger.getLogger("Forex");
String dbUrl = "jdbc:mysql://localhost/pfx";
String dbClass = "com.mysql.jdbc.Driver";
String ins = "insert into live_forex(watuta_rodzaj, kurs_walut) values(1,?)";
String urlcsv = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=EURUSD=X";
public int init() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, "root", "haslo");
if (con.isClosed()) {
logger.severe("utworzone polaczenie jest zamkniete");
return -1;
}
return 0;
} catch (Exception e) {
logger.log(Level.SEVERE, "init", e);
return -1;
}
}
public void close() {
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
logger.log(Level.SEVERE, "init", e);
}
}
@Override
public void run() {
logger.info("start run");
try {
if (con.isClosed()) {
logger.severe("polaczenie jest zamkniete");
init();
}
URL url;
URLConnection urlConn;
DataInputStream dis;
url = new URL(urlcsv);
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
dis = new DataInputStream(urlConn.getInputStream());
String s;
while ((s = dis.readLine()) != null) {
logger.info("porabelm " + s);
String[] tab = s.split(",");
PreparedStatement pstmt = con.prepareStatement(ins);
pstmt.setString(1, tab[1]);
pstmt.executeUpdate();
}
dis.close();
// }
logger.info("koniec interacji");
} catch (Exception e) {
logger.log(Level.SEVERE, "run", e);
}
}
}
program uruchamia się co sekunde na serwerze i pobiera dane Eur/usd i dodaje do bazy i zużywa coraz więcej pamięci, ktoś wie gdzie tkwi problem?
z góry dzięki za odp