# 10-July-2019 ## About Spring Scheduling ### reference: https://spring.io/guides/gs/scheduling-tasks/ ### reference2: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html 1. main program ``` @EnableScheduling ``` 2. any component ``` @Scheduled(cron=". . .") ``` 3. https://start.spring.io/ * gradle * java * 2.1.6 * web 4. sample code ``` @SpringBootApplication @EnableScheduling public class DemoApplication { private static final Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class); public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Scheduled(cron="20 * * * * *") public void demoCronLog() { LOGGER.info("logger fired!"); } } ``` 5. Mutability * immutable (str, int, float, boolean, unicode...tuple) * mutable (list, set, dict, object) ``` l1 = ['A', 'B', 'C', 'D', 'E'] l2 = l1 l3 = l1[:] l4 = list(l1) # will generate a new object print 'l1 address = %s' % (hex(id(l1))) print 'l2 address = %s' % (hex(id(l2))) print 'l3 address = %s' % (hex(id(l3))) print 'l4 address = %s' % (hex(id(l4))) print l1, l2, l3, l4 l1[0] = 'a' l2[1] = 'b' print l1, l2, l3, l4 ``` ``` set1 = {'A', 'P', 'P', 'L', 'E'} set2 = set(list('BANANA')) print set1, set2 print set1 | set2 # union print set1 & set2 # intersection print set1 ^ set2 # XOR set3 = set(list("CITRON")) set4 = set(list("DONULT")) for x in set4: set3.add(x) print set3 set3.add(set4) ``` ``` class Course: def __init__(self, name, hour, instructor): self.name = name self.hour = hour self.instructor = instructor def __str__(self): return "[%s]%d by %s" % (self.name, self.hour, self.instructor) def __repr__(self): return "(R)" + str(self) def __hash__(self): return hash("[%s]%d(%s)" % (self.name, self.hour, self.instructor)) def __eq__(self, other): return self.name == other.name \ and self.hour == other.hour \ and self.instructor == other.instructor c1 = Course("spring boot", 35, "Mark Ho") s1 = {c1} print c1 print type(s1), s1 c2 = c1 s1.add(c2) print s1 c3 = Course("spring boot", 35, "Mark Ho") s1.add(c3) print s1 c4 = Course("spring boot", 42, "Mark Ho") s1.add(c4) print s1 print hex(hash(c1)), hex(hash(c2)), hex(hash(c3)) ```