{"id":2785,"date":"2022-08-30T15:27:45","date_gmt":"2022-08-30T15:27:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/16\/deleting-a-record-after-a-period-of-time-or-when-the-specified-time-reaches-automatically-in-java-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:27:45","modified_gmt":"2022-08-30T15:27:45","slug":"deleting-a-record-after-a-period-of-time-or-when-the-specified-time-reaches-automatically-in-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/deleting-a-record-after-a-period-of-time-or-when-the-specified-time-reaches-automatically-in-java-collection-of-common-programming-errors\/","title":{"rendered":"Deleting a record after a period of time or when the specified time reaches automatically in Java-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m developing a Java web application. The scenario is described below:<\/p>\n<ul>\n<li>\n<p>Many users submit their status and they can see others&#8217; statuses as well. It looks like a kind of social network.<\/p>\n<\/li>\n<li>\n<p>Their statuses have a period of time to display, after this period, their statuses in database will be deleted.<\/p>\n<\/li>\n<li>\n<p>At the time their statuses are deleted, send a notification to all users to request an update (the deleted statuses have to be vanished in realtime!)<\/p>\n<\/li>\n<\/ul>\n<p>I&#8217;ve tried to do that automatically by a thread in the Java web application. However, I&#8217;m stuck at some problems:<\/p>\n<p>+Is it possible to manage database like that? I&#8217;ve thought of database event, but when a record is deleted, I will not be noticed.<\/p>\n<p>+I&#8217;m using web socket to make the application work in realtime. If a person update a new status or change it, it&#8217;s possible to send an update notification to all of the users by using web socket. But when the changes come from database, I don&#8217;t know how to send a notification like that.<\/p>\n<p>Can you give me some ideas? Thank you in advanced!<\/p>\n<ol>\n<li>\n<p>You can use <code>DelayQueue<\/code> to store each item to be removed at a specified delay,and when you are removing the item,remove the record in database and send a notify to browser.<\/p>\n<\/li>\n<li>\n<p>If you need the statuses to be deleted even if your program crashes, then I recommend that you use quartz &#8211; this way if your program crashes then quartz will update the database when you re-load your program. If your program doesn&#8217;t need to be this robust then use a DelayQueue instead.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-16 13:16:47. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m developing a Java web application. The scenario is described below: Many users submit their status and they can see others&#8217; statuses as well. It looks like a kind of social network. Their statuses have a period of time to display, after this period, their statuses in database will be deleted. At the time their [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2785","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2785"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2785\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}