Network Programming udp operation learning notes, udp learning notes

Source: Internet
Author: User

Network Programming udp operation learning notes, udp learning notes
The core is about idempotent operation learning.

package com.udp;public class ThreadRun implements  Runnable {    private boolean flag = true;    @Override    public void run() {        for (int i = 0 ; i< Integer.MAX_VALUE && flag ; i++){            System.out.println("i = " + i);        }    }    public void cancel(){        flag = false;    }}
Package com. udp; import java. io. fileNotFoundException; import java. io. fileOutputStream; import java. io. IOException; import java. util. timer; import java. util. timerTask;/** idempotent operations, A ^ n = A, idempotent operations, A method is called multiple times, just like a method called once */public class suplement {public static void main (String [] args) {/* // a method is called multiple times. It is the same as a method called once. ThreadRun threadRun = new ThreadRun (); new Thread (threadRun ). start (); new Timer (). schedule (new TimerTask () {@ Override public void run () {threadRun. cancel () ;}}, 3000); * // try-with-resouce try (// The method in applying for resource Auto Closeable is a non-idempotent operation, so either try_with_resource FileOutputStream fos = new FileOutputStream ("a.txt") // only the closeable or AutoClosesable subclass can be placed in parentheses. // int I = 0;) {fos. write ("hello ". getBytes ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} finally {// either close the stream resource here. // select either of them }}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.