NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.blog.server.blog.serviceImpl;

import java.net.InetAddress;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.joda.time.DateTime;
import org.joda.time.Seconds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.blog.server.blog.dao.DummyEntityDAO;
import com.blog.server.blog.dao.ScheduleTrackerDAO;
import com.blog.server.blog.entities.DummyEntity;
import com.blog.server.blog.entities.ScheduleTracker;
import com.blog.server.blog.service.ScheduleService;

@Component
public class ScheduleServiceImpl implements ScheduleService {

@Autowired
private ScheduleTrackerDAO dao;

@Autowired
private DummyEntityDAO dummyDAO;

private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5);

// @PostConstruct
public void getAnomalyRules(String hostName) throws ParseException {
System.out.println("running");
System.out.println("running run method");
String scheduledTime = "10:56:00";
Long scheduleFrequency = 20L;
System.out.println(scheduleFrequency);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
DateTime d = new DateTime();
DateTime d5 = new DateTime(d.getYear(), d.getMonthOfYear(), d.getDayOfMonth(), 10, 56, 00);
Long lockAtLeastTime = 50L;
// ScheduleTracker s = new ScheduleTracker(a, System.currentTimeMillis(), System.currentTimeMillis() + 20,
// "schedule");
Date d2 = sdf.parse(d.toString("dd-MM-yyyy") + " " + scheduledTime);
// ScheduleTracker s2 = dao.saveScheduleTracker(s);
Date d3 = Calendar.getInstance().getTime();
Seconds difInSeonds = Seconds.secondsBetween(d, d5);
long dif = (d2.getTime() - d3.getTime()) / 1000;
final Runnable scheduledJob = new Runnable() {
public void run() {
System.out.println("inside run");
ScheduleTracker s2 = null;
ScheduleTracker s = null;
DateTime d5 = new DateTime();
// if (s == null || (s.getLockUntil() < System.currentTimeMillis() && !s.getIsRunning())) {
// ScheduleTracker s3 = new ScheduleTracker(a, System.currentTimeMillis(),note
// System.currentTimeMillis() + 20, "schedule");
// s3.setId(s.getId());
try {
String sName = InetAddress.getLocalHost().getHostName();
System.out.println(sName);
s = dao.getScheduleTracker(d5.toString());
ScheduleTracker s3 = null;
if (s == null) {
s2 = new ScheduleTracker(hostName, System.currentTimeMillis(), d5.toString(), "schedule", true);
try {
s3 = dao.saveScheduleTracker(s2);
} catch (Exception e) {
e.printStackTrace();
}
}
if (s3 != null && s3.equals(s2) && (s3.getName() != sName && !s.getIsRunning())) {
System.out.println("calling from" + hostName + " " + Thread.currentThread().getName());
Thread.sleep(1000);
DummyEntity d = new DummyEntity();
d.setName(hostName);
dummyDAO.saveEntity(d);
System.out.println("done" + hostName);
}
// if (s == null) {
// System.out.println("inside run if");
// s = new ScheduleTracker(hostName, System.currentTimeMillis(),
// System.currentTimeMillis() + lockAtLeastTime, "schedule", true);
// s = dao.saveScheduleTracker(s);
// } else {
// s.setName(hostName);
// s.setLockAt(System.currentTimeMillis());
// s.setLockUntil(System.currentTimeMillis() + lockAtLeastTime);
// s.setIsRunning(true);
// ScheduleTracker s3 = dao.updateScheduleTracker(s);
// }

} catch (Exception e) {
e.printStackTrace();
} finally {
// ScheduleTracker s5 = new ScheduleTracker(a, System.currentTimeMillis(),
// System.currentTimeMillis(), "schedule", false);
// s5.setId(s.getId());
// Long executionTime = System.currentTimeMillis() - s.getLockAt();
// if (executionTime > lockAtLeastTime) {
// s.setLockUntil(System.currentTimeMillis());
// }
// s.setIsRunning(false);
// s.setIsRunning(false);
// ScheduleTracker s4 = dao.updateScheduleTracker(s);

}
// }
}
};

final ScheduledFuture<?> scheduledJobHandler = scheduler.scheduleAtFixedRate(scheduledJob, 30, 10,
TimeUnit.SECONDS);
scheduler.schedule(new Runnable() {
public void run() {
scheduledJobHandler.cancel(true);
}
}, 60 * 60, TimeUnit.SECONDS);
}

@PostConstruct
public void runThreads() {
// CountDownLatch latch = new CountDownLatch(1);
// Thread t1 = new Thread(new Runnable() {
//
// @Override
// public void run() {
// try {
// latch.await();
// System.out.println(Thread.currentThread().getName());
// getAnomalyRules("thread1");
// } catch (InterruptedException | ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// }
//
// });
// Thread t2 = new Thread(new Runnable() {
//
// @Override
// public void run() {
// try {
// latch.await();
// System.out.println(Thread.currentThread().getName());
// getAnomalyRules("thread2");
// } catch (InterruptedException | ParseException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// });
// t2.start();
// t1.start();
// latch.countDown();
try {
getAnomalyRules("7070");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public String startScheduleJob(String name) {
try {
getAnomalyRules("8080");
} catch (Exception e) {
e.printStackTrace();
}
return "started";
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.