0
I am making a "website" in GAE Java version to serve as a notifier when a source with results that I am waiting for goes online. You’re supposed to check the link in question every 24 hours. I already have everything working, but as usual, the site is "loading" until you pass the waiting time limit I set (for test purposes, set 10 seconds). Now if the site has to stay charging for 24 hours until it comes time to check the site again, the browser will give me timeout or else I have to have a connected computer uploading the website, which goes against the whole purpose!
It is possible to make the program run on background there on the GAE servers if I put a thread prosecuting?
I have the following code working:
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
connection();
timer();
System.out.println("shit");
}
private void timer() throws IOException{
if((lastcheckedDate + (10000)) > System.currentTimeMillis())
{
waiting();
}
}
private void check () throws IOException{
connection();
if (code==200)
{
sendMessage();
}
else if (code==404){
System.out.println("Still not available");
timer();
}
}
private void waiting() throws IOException{
while((lastcheckedDate + (10000)) > System.currentTimeMillis())
{
}
check();
}
private void sendMessage() throws UnsupportedEncodingException{
System.out.println("Sending email notification");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props,null);
String msgBody = "The Vulcanus in Japan Shortlist seems to be available. Check the following link: " +
URL;
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]", "Notifier"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]", "ipunna"));
msg.setSubject("Change in x link");
msg.setText(msgBody);
Transport.send(msg);
}catch (AddressException e) {
System.out.println("Address Exception occured");
}catch (MessagingException e){
System.out.println("Messaging Exception occured");
}
}
private void connection() throws IOException{
URL vjselec = new URL(URL);
connection = (HttpURLConnection)selec.openConnection();
connection.setRequestMethod("GET");
connection.connect();
code = connection.getResponseCode();
lastcheckedDate = connection.getDate();
System.out.println("first Date: " + lastcheckedDate);
connection.disconnect();
}
Have you seen how the Tasksqueues in GAE? I think it can help you, although I don’t quite understand what you want to do.
– Miguel Cartagena