tianboguang преди 3 години
родител
ревизия
b2101e8cc1

+ 1 - 36
4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/OssFileService.java

@@ -82,10 +82,6 @@ public class OssFileService extends AbstractFYunFileService {
             log.error("oss上传文件失败", e);
             e.printStackTrace();
             return null;
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -131,10 +127,6 @@ public class OssFileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("OSS删除文件失败,key=" + remoteFolderPath);
             e.printStackTrace();
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -146,10 +138,6 @@ public class OssFileService extends AbstractFYunFileService {
             }
         } catch (Exception e) {
             log.error("OSS批量上传文件失败!");
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -185,10 +173,6 @@ public class OssFileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("获取文件列表失败,path=" + sourcePath, e);
             e.printStackTrace();
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
         return keyList;
     }
@@ -209,10 +193,6 @@ public class OssFileService extends AbstractFYunFileService {
             });
         } catch (Exception e) {
             log.error("列举文件目录失败,key=" + sourcePath);
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -227,10 +207,6 @@ public class OssFileService extends AbstractFYunFileService {
             }
         } catch (Exception e) {
             log.error("批量复制文件失败!");
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -249,14 +225,11 @@ public class OssFileService extends AbstractFYunFileService {
             } catch (IOException e) {
                 log.error("读取scene.json文件流失败", e);
             }
+            ossObject.close();
             return contentJson.toString();
         } catch (Exception e) {
             log.error("获取文件内容失败:{}", remoteFilePath);
             return null;
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -267,10 +240,6 @@ public class OssFileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("判断文件是否存在失败:{}", objectName);
             return false;
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 
@@ -291,10 +260,6 @@ public class OssFileService extends AbstractFYunFileService {
         } catch (Throwable throwable) {
             log.error("文件下载失败:{}", remoteFilePath);
             throwable.printStackTrace();
-        } finally {
-            if (!ObjectUtils.isEmpty(ossClient)) {
-                ossClient.shutdown();
-            }
         }
     }
 

+ 1 - 1
4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/config/OssConfig.java

@@ -16,7 +16,7 @@ public class OssConfig {
     private FYunFileConfig fYunFileConfig;
 
     /**
-     * 配置多实例,且使用时候要手动shutdown,否则会造成内存溢出
+     * new OSSClient操作完成后,请通过shutdown进行关闭,保证new OSSClient和ossClient.shutdown成对使用。
      * @return
      */
     @Bean

+ 1 - 44
4dkankan-utils-fyun-s3/src/main/java/com/fdkankan/fyun/s3/S3FileService.java

@@ -39,10 +39,6 @@ public class S3FileService extends AbstractFYunFileService {
             return fYunFileConfig.getHost().concat(remoteFilePath);
         } catch (Exception e) {
             log.error("s3上传文件失败", e);
-        } finally {
-            if (s3 != null) {
-                s3.shutdown();
-            }
         }
         return null;
     }
@@ -91,10 +87,6 @@ public class S3FileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("文件上传失败:{}",filePath);
             e.printStackTrace();
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
         return null;
     }
@@ -123,10 +115,6 @@ public class S3FileService extends AbstractFYunFileService {
             s3.deleteObject(bucket, remoteFilePath);
         } catch (Exception e) {
             log.error("s3删除文件失败,key=" + remoteFilePath, e);
-        } finally {
-            if (s3 != null) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -157,10 +145,6 @@ public class S3FileService extends AbstractFYunFileService {
             } while (objectListing.isTruncated());
         } catch (Exception e) {
             log.error("删除was文件失败,path=" + remoteFolderPath, e);
-        } finally {
-            if (s3 != null) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -172,10 +156,6 @@ public class S3FileService extends AbstractFYunFileService {
             }
         } catch (Exception e) {
             log.error("OSS批量上传文件失败!");
-        } finally {
-            if (!ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -208,10 +188,6 @@ public class S3FileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("获取文件列表失败,path=" + sourcePath, e);
             e.printStackTrace();
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
         return keyList;
     }
@@ -234,10 +210,6 @@ public class S3FileService extends AbstractFYunFileService {
             });
         } catch (Exception e) {
             log.error("列举文件目录失败,key=" + sourcePath);
-        } finally {
-            if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -252,10 +224,6 @@ public class S3FileService extends AbstractFYunFileService {
             }
         } catch (Exception e) {
             log.error("批量复制文件失败!");
-        } finally {
-            if (!ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -275,14 +243,11 @@ public class S3FileService extends AbstractFYunFileService {
 			} catch (IOException e) {
 				log.error("读取aws文件流失败", e);
 			}
+            object.close();
 			return content.toString();
         } catch (Exception e) {
             log.error("获取文件内容失败:{}", remoteFilePath);
             return null;
-        } finally {
-            if (!ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -293,10 +258,6 @@ public class S3FileService extends AbstractFYunFileService {
         } catch (Exception e) {
             log.error("判断文件是否存在失败:{}", objectName);
             return false;
-        } finally {
-            if (!ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 
@@ -312,10 +273,6 @@ public class S3FileService extends AbstractFYunFileService {
         } catch (Throwable throwable) {
             log.error("文件下载失败:{}", remoteFilePath);
             throwable.printStackTrace();
-        } finally {
-            if (!ObjectUtils.isEmpty(s3)) {
-                s3.shutdown();
-            }
         }
     }
 }