Java-based code snippet failure strategy protection method and device

A code fragment and strategy technology, applied in the basic field, can solve the problems of complicated writing, reduce code maintainability, code repetition, etc., and achieve the effect of improving code maintainability, strong readability, and strong scalability

Pending Publication Date: 2022-01-04
GUANGZHOU JOIWAY INFORMATION SCI & TECHCO LTD
View PDF0 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

In the traditional development method, it is necessary to encapsulate code fragments into methods, and write try catch statements to handle various situations. For some complex strategies, wri

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Java-based code snippet failure strategy protection method and device
  • Java-based code snippet failure strategy protection method and device
  • Java-based code snippet failure strategy protection method and device

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0015] In order to make the technical means, creative features, goals and effects achieved by the present invention easy to understand, the present invention will be further described below in conjunction with specific embodiments.

[0016] refer to figure 1 , the present embodiment adopts the following technical solutions: a method for Java-based code fragment failure policy protection, the steps of which are:

[0017] (1) Encapsulate the container class that transmits the result value and exception at the same time.

[0018]

[0019]

[0020] (2) Abstract a given code fragment as an execution context.

[0021]

[0022]

[0023] (3) Define the strategy interface. The strategy needs to be implemented to get an execution context (Execution) and return its execution result or exception.

[0024] public interface Policy {

[0025] Either execute(Execution execution);

[0026] }

[0027] (4) An executor for constructing policy combinations, allowing multiple...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention discloses a Java-based code snippet failure strategy protection method and device, and relates to the technical field of foundations. The method comprises the following steps of: packaging a container class which transmits a result value and an exception at the same time, abstracting a given code snippet as an execution context, defining a strategy interface, returning an execution result or abnormity of a strategy after the execution context is obtained for the strategy to be realized, constructing an executor of a strategy combination, allowing a plurality of strategies to be nested and combined into a composite strategy according to an incoming sequence; creating various strategies according to needs, and realizing a Policy interface; and assembling multiple strategies and transmitting into the code snippets. According to the method, failure strategy protection which is high in readability, high in expansibility, reusable and configurable is adopted for the specified code snippets, the code maintainability is improved, and the application prospect is wide.

Description

technical field [0001] The present invention relates to the field of basic technologies, in particular to a Java-based code segment failure policy protection method and device. Background technique [0002] Code fragment failure policy protection means that in daily development, it is often necessary to implement a series of strategies for specific code fragments (such as obtaining remote or local resources, initiating remote or local calls, etc.), such as automatic retry when failure occurs , timeout return, fallback to use pocket resources, etc. In the traditional development method, it is necessary to encapsulate code fragments into methods, and write try catch statements to handle various situations. For some complex strategies, writing try catch statements will be extremely complicated. At the same time, because these strategies cannot be reused, there are many places in the code. Recurrence reduces code maintainability. In order to solve the above problems, it is par...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
IPC IPC(8): G06F8/36
CPCG06F8/36
Inventor 王锐旭张辉张健焜
Owner GUANGZHOU JOIWAY INFORMATION SCI & TECHCO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products