TWSz Java API Set duration - java

When I try set duration using this code:
Job job = new Job();
job.setName("5");
long dur = 1000;
job.setEstimatedDuration(1000);
job.setPriority(-1);
ZOSJobDefinition jobDef = new ZOSJobDefinition();
jobDef.setFlowTargetKey(new FlowTargetKey("CPU1"));
jobDef.setTaskType(TaskTypes.ZOS_JOB_TASK);
jobDef.setJclName("DMSORT");
job.setJobDefinition(jobDef);
I get error EQQX489E THE DURATION OF OPERATION CPU1 5 IS INVALID, 0 SEC*100.
I do it in the same way like in the documentation, however, I try also:
long dur = Long.valueOf(1000);
job.setEstimatedDuration(dur);
and
long dur = 1000L;
job.setEstimatedDuration(dur);
but I still get the same error.

There is wrong example in documentation. Solution is:
Job job = new Job();
job.setName("5");
job.setPriority(1);
**//job.setEstimatedDuration(1000);**
ZOSJobDefinition jobDef = new ZOSJobDefinition();
jobDef.setFlowTargetKey(new FlowTargetKey("CPU1"));
jobDef.setTaskType(TaskTypes.ZOS_JOB_TASK);
jobDef.setJclName("DMSORT");
**jobDef.setNormalElapsedTime(1000L);**
job.setJobDefinition(jobDef);

Related

How to schedule a task which checks for an Email every 15 min. If mail is found, then task should end and only execute the next day using Java

public static void main(String[] args) throws Exception {
String saveDirectorySib = PropertiesHolder.getInstance().getProperty(PropertiesHolder.SIB_Txt_FOLDER_KEY);
JobDetail Job = JobBuilder.newJob(SibCronScheduler.class).build();
Trigger t1 = TriggerBuilder.newTrigger().withIdentity("CronTrigger")
.withSchedule(CronScheduleBuilder.cronSchedule(PropertiesHolder.getInstance().getProperty(PropertiesHolder.schedulerExec))).build();
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
sched.start();
sched.scheduleJob(Job, t1);
EmailFoundBoolean mailFetch = new EmailFoundBoolean();
boolean mailFound = mailFetch.emailFoundValueReturn();
System.out.println("Value is"+mailFound);
if(mailFound== true)
{ System.out.println(mailFound);
// sched.deleteJob(Job.getKey());
// sched.pauseJob(Job.getKey());
sched.standby();
System.out.println("Process completed for the day.");
}
else
{
System.out.println("Process continues");
}
public class SibCronScheduler implements Job{
#Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// Timer time = new Timer();
// ScheduledTask st = new ScheduledTask();
// time.schedule(st, 9000,1000 * 60 * 15);
System.out.println("Checking for the mail from South Indian Bank....");
String saveDirectorySib = PropertiesHolder.getInstance().getProperty(PropertiesHolder.SIB_Txt_FOLDER_KEY);
mailRead.setSaveDirectory1(saveDirectorySib);
try {
mailRead.sibEmailReader();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I tried Java scheduler and quartz scheduler. Using java scheduler the code runs every 15 min. But still it does not work. I need to run the process every day from 6 pm to 12 am. every 15 min. And if the mail is found. stop the scheduler for the day and restart the process the next day at 6 pm. Syste.exit(0) stops the code but I need to restart it the next day.
You said:
I need to run the process every day from 6 pm to 12 am. every 15 min. And if the mail is found. stop the scheduler for the day and restart the process the next day at 6 pm.
You could simplify your problem by scheduling a task to run every 15 minutes around the clock. Let that task check (a) whether the daily chore was performed, and (b) the time-of-day and date.
The idea here is to let you task run needlessly, but ever so briefly, around the clock. Checking the current moment, and comparing to when the chore was last performed, take a minuscule amount of CPU time and memory. So there really is no point to bothering with suspending the checks for part of each day.
public class EveningEmailCheckingTask implements Runnable
{
final private ZoneId zoneId;
final private LocalTime startTime ;
private ZonedDateTime whenEmailRetrieved;
public EveningEmailCheckingTask( final ZoneId z , final LocalTime lt )
{
this.zoneId = Objects.requireNonNull( z ) ;
this.startTime = Objects.requireNonNull( lt ) ;
this.whenEmailRetrieved = ZonedDateTime.now( this.zoneId ).minusDays( 1 ) ; // Initialize a value so our main code can skip null check.
}
#Override
public void run()
{
ZonedDateTime now = ZonedDateTime.now( this.zoneId ) ;
// See if chore has been completed successfully today.
LocalDate then = this.whenEmailRetrieved.toLocalDate() ;
LocalDate today = now.toLocalDate() ;
if( then.isBefore( today ) )
{
if( now.toLocalTime().isBefore( this.startTime ) ) { return ; }
// … Perform chore.
// … If email received, update `this.whenEmailRetrieved`.
}
else if( then.isEqual( today ) )
{
return ; // Daily chore already performed.
}
else if( then.isAfter( today ) )
{
// Houston, we have a problem. The task was performed in the future.
}
else
{
// Should never reach this point. Defensive check in case our if-tests above are flawed.
}
}
}
Instantiate.
EveningEmailCheckingTask task = new EveningEmailCheckingTask( ZoneId.of( "Asia/Kolkata" , LocalTime.of( 18 , 0 ) ) ;
Create a ScheduledExecutorService, and remember it. You’ll need to shutdown that service before your app exits, otherwise the backing thread pool can continue indefinitely like a zombie 🧟‍♂️.
ScheduledExecutorService ses = Executors. … ;
Schedule your task.
ses.scheduleAtFixedRate( … ) ;

Ical4j. RFC5545. Calculate event occurrences, duration hack

I check ical4j library. At time I need calculate event occurrences. Useful example to calculate is here. I try to shift start date and end date. In original start date is 20101113 - 2010 November, Saturday (it maps on pattern see BYDAY=...SA). I want do not care if start match or not. So I used start date with value 20101112 - 2010 November, Friday (it doesn't map on any day in pattern see BYDAY=MO,TU,SA)
VEvent event = new ContentBuilder().vevent {
dtstart('20101112', parameters: parameters() {value('DATE')})
dtend('20101113', parameters: parameters() {value('DATE')})
rrule('FREQ=WEEKLY;WKST=MO;INTERVAL=3;BYDAY=MO,TU,SA')
}
def dates = event.calculateRecurrenceSet(new Period('20101101T000000/20110101T000000'))
println dates
result is
[20101112T000000Z/20101113T000000Z, 20101113T000000Z/P1D, 20101129T000000Z/P1D, 20101130T000000Z/P1D, 20101204T000000Z/P1D, 20101220T000000Z/P1D, 20101221T000000Z/P1D, 20101225T000000Z/P1D]
almost as expected (except first period in result 20101112T000000Z/20101113T000000Z is redundant). So I continue investigate how to exclude one. In debug mode I see
result = {PeriodList#1497} size = 8
0 = {Period#2240} "20101112T000000Z/20101113T000000Z"
duration = null
rangeStart = {DateTime#2243} "20101112T000000Z"
rangeEnd = {DateTime#2244} "20101113T000000Z"
1 = {Period#2264} "20101113T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2285} "20101113T000000Z"
rangeEnd = {DateTime#2286} "20101114T000000Z"
2 = {Period#2265} "20101129T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2290} "20101129T000000Z"
rangeEnd = {DateTime#2291} "20101130T000000Z"
3 = {Period#2266} "20101130T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2295} "20101130T000000Z"
rangeEnd = {DateTime#2296} "20101201T000000Z"
4 = {Period#2267} "20101204T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2300} "20101204T000000Z"
rangeEnd = {DateTime#2301} "20101205T000000Z"
5 = {Period#2268} "20101220T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2315} "20101220T000000Z"
rangeEnd = {DateTime#2316} "20101221T000000Z"
6 = {Period#2269} "20101221T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2310} "20101221T000000Z"
rangeEnd = {DateTime#2311} "20101222T000000Z"
7 = {Period#2270} "20101225T000000Z/P1D"
duration = {Dur#2284} "P1D"
rangeStart = {DateTime#2305} "20101225T000000Z"
rangeEnd = {DateTime#2306} "20101226T000000Z"
Eureka! I've found marker to detect redundant dates in generated set (corrupted period has null duration). I continue handling it filtering periods with null value. But filter have filtered nothing. Continue checking...
package net.fortuna.ical4j.model;
...
public class Period extends DateRange implements Comparable<Period> {
private static final long serialVersionUID = 7321090422911676490L;
private Dur duration;
...
public final Dur getDuration() {
if (duration == null) {
return new Dur(getStart(), getEnd());
}
return duration;
}
...
as you can see, class Period has private Dur duration and public final Dur getDuration(). I can't access duration without workaround...
Question is
How should I do?
Use reflection hack to get duration - ugly solution.
Download library sources to change Period class and rebuild library - follows bad support new library versions.
Ask to ical4j developers to expand Period facade - it needs time to change and for release.
Use duration hack over toString (it's unreliable solution).
I've raised issue. I'will add details if they consider the issue.

How to obtain , record and duration of app usage in minutes , seconds or hours

I have block of code that allows me to retreive all the apps/services running on my android device including the app that I
am building. I am not entirely sure if I am on the right path butbecause I am debugging on android 4.3 I would like to use ActivityManager.RunningService.activeSince
(per service/app) and subtract it from SystemClock.elapsedRealtime(); which I understand is total milliseconds since reboot . So for example
if the device was rebboted at 10am and whatsapp was started at 10:15 and the current time is 1030 I want to be able to use these values
to get an a close estimate of the amount spent on whatsapp. I have a feeling that this is not the most elegant way to achieve this and I am therefore very open to
any advice. This my code below thus far . For now I am using android 4.3
ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
for (ActivityManager.RunningServiceInfo info : services) {
cal.setTimeInMillis(currentMillis-info.activeSince);
long millisSinceBoot = SystemClock.elapsedRealtime();
long appStartTime = info.activeSince;
long appDuration = appStartTime - millisSinceBoot ;
//long time = ((millisSinceBoot - values.get(position).activeSince)/1000);
//long time = ((millisSinceBoot - currentMillis-info.activeSince)/1000);
//Log.i("HRHHRHRHRHR", "%%%%%%%%%%%%%%%%"+time);
//String time1 = String.valueOf(time);
int seconds = (int) (appDuration / 1000) % 60 ;
int minutes = (int) ((appDuration / (1000*60)) % 60);
int hours = (int) ((appDuration / (1000*60*60)) % 24);
String time11 = hours+":"+minutes+":"+seconds;
Log.i("Time", "Secs:- " + seconds + " " + "Mins:- " + minutes + " " + "Hours:- " + hours);
Log.i(TAG, String.format("Process %s with component %s has been running since %s (%d milliseconds)",
info.process, info.service.getClassName(), cal.getTime().toString(), info.activeSince ));
}

Performance issue in Converting Java object to JSON object

I have tested below example before I do my exact task of converting Java Objects to JSON.
Converting Java objects to JSON with Jackson
And I was looking for the better performance (Converting time should be very less).
This article is showing the stats for the performance in between different APIs from this answer.
My finding was for example with the first link that I mentioned (with few records):
ValueData object = new ValueData();
List<ValueItems> information = new ArrayList<ValueItems>();
ValueItems v1 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat1", 1, "data1");
ValueItems v2 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat2", 2, "data2");
ValueItems v3 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat3", 3, "data3");
ValueItems v4 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat4", 4, "data4");
ValueItems v5 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat5", 5, "data5");
ValueItems v6 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat6", 6, "data6");
ValueItems v7 = new ValueItems(String.valueOf(Calendar.getInstance().getTimeInMillis()), "feat7", 7, "data7");
information.add(v1);
information.add(v2);
information.add(v3);
information.add(v4);
information.add(v5);
information.add(v6);
information.add(v7);
object.setInformation(information);
And I'm going to convert this object by using Jackson:
long smili = Calendar.getInstance().getTimeInMillis();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);
long emili = Calendar.getInstance().getTimeInMillis();
System.out.println("taken time using jackson = " + (emili - smili) + " milli seconds");
And now I'm doing by using StringBuilder:
smili = Calendar.getInstance().getTimeInMillis();
StringBuilder sb = new StringBuilder();
sb.append("{\n\"information\" : [\n");
for (ValueItems vi : object.getInformation()) {
sb.append("{\n\"timestamp\" : \""+vi.getTimestamp()+"\",");
sb.append("\"feature\" : \""+vi.getFeature()+"\",");
sb.append("\"ean\" : "+vi.getEan()+",");
sb.append("\"data\" : \""+vi.getData()+"\"\n},");
}
sb.deleteCharAt(sb.length() - 1);
sb.append("]\n}");
emili = Calendar.getInstance().getTimeInMillis();
System.out.println("taken time using StringBuilder = " + (emili - smili) + " milli seconds");
I got the timing as given below just for the list size 7:
taken time using jackson = 534 milli seconds
taken time using StringBuilder = 1 milli seconds
I want to convert the object with the information list size more than 10k but the time should be very less.
Creating JSON buy using StringBuilder will help in this case?
Is there other API gives the facility that I require?
Please help me on this.
Thanks Sam B.
I have tried with jakson-afterburner:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new AfterburnerModule());
ow = mapper.writer().withDefaultPrettyPrinter();
json = ow.writeValueAsString(object);
And I have tested with list sizes 7, 7000, 70000 and 700000:
timing was:
For 7:
taken time using jackson = 217 milli seconds
taken time using StringBuilder = 1 milli seconds
taken time using after-burner = 25 milli seconds
For 7000:
taken time using jackson = 310 milli seconds
taken time using StringBuilder = 31 milli seconds
taken time using after-burner = 65 milli seconds
For 70000:
taken time using jackson = 469 milli seconds
taken time using StringBuilder = 149 milli seconds
taken time using after-burner = 101 milli seconds
For 700000:
taken time using jackson = 1120 milli seconds
taken time using StringBuilder = 705 milli seconds
taken time using after-burner = 623 milli seconds
When the list size increases, afterburner is efficient.

Convert seconds to W,D,H,M format in JAVA

I have time in seconds i want to convert it into a format like 6w 3d 9h 5m . Can someone please provide a method which can do this task. Thanks :)
w=weeks
d=days
h=hours
m=minutes
I have tried the below code but i dont get weeks using
int day = (int)TimeUnit.SECONDS.toDays(seconds);
long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.SECONDS.toHours(TimeUnit.SECONDS.toDays(seconds));
long minute = TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.SECONDS.toMinutes(TimeUnit.SECONDS.toHours(seconds));
System.out.println("Day :"+day+" Hours :"+hours+" Minutes :"+minute);
this will give you:
1w 4d 10h 20m
there should be more elegant way, but this works:
long s = 987654l;
final long M=60,H=60*M, D=24*H, W=7*D;
long w = s/W;
s%=W;
long d = s/D;
s%=D;
long h = s/H;
s%=H;
long m = s/M;
System.out.printf("%dw %dd %dh %dm",w,d,h,m);
int seconds=98765410;
int weeks = (int) (TimeUnit.SECONDS.toDays(seconds) / 7);
int days = (int) (TimeUnit.SECONDS.toDays(seconds) - 7 * weeks);
long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(days) - TimeUnit.DAYS.toHours(7*weeks);
long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60);
System.out.println(weeks+"w "+days+"d "+hours+"h "+minutes+"m");
Will print out:
163w 2d 2h 50m

Categories

Resources